0

Can one time pad cipher implemented for numbers? if yes, can you tell me the algorithm or the working code (preferably java) for the same?

Also, what is the difference between one time pad and xor cipher.

Debopam
  • 3,198
  • 6
  • 41
  • 72
  • please define "xor cipher" ... just xor with a static byte? – DarkSquirrel42 Apr 29 '19 at 21:35
  • Yes. xoring keyyte[i] and inputbyte[i] – Debopam Apr 29 '19 at 21:44
  • Strange question. Don't you know that everything can be represented by bits? Just convert your numbers into bits. X-or cipher is the general case where you can convert it into OTP or stream cipher. `When the keystream is generated by a pseudo-random number generator, the result is a stream cipher. With a key that is truly random, the result is a one-time pad, which is unbreakable in theory. ` – kelalaka Apr 29 '19 at 22:04

1 Answers1

1

OTP and what you describe as xor cipher are the same if (and only if) the following assumptions are true:

  • your key is at least as large as the plaintext (in other words: there is at least one unique key bit for every plaintext bit)
  • your key consists of equally distrubuted true random binary data
  • your key is never reused
  • your key is kept secret

those are some pretty heavy assumptions

for example, if you want to encrypt a DVD, your key will also be as large as one DVD, which has to be securely transferred to the recipient, also that key DVD may only be used for this single data exchange and may never be reused

you may not simply create the random bits by using the random class ... OTP demands TRUE randomness ... no pseudo random number generator... not even a cryptographically secure one... the OTP definition asks for true random values ... why not even a CSPRNG? because the strength of OTP is being unbreakable ... as soon as you rely on something less than a true random source, the overall cryptographic strength goes down from infinite to the cryptographic strength of the CSPRNG ... which may be a cryptographic strength that is quite good, but finite ... it might be possible to break it... for real OTP, it has been prooven that even with infinite resources, the system is not breakable from the information theory side, which is remarkable, because it is the ONLY known cryptosystem with this property

OTP usually is impracticable for our usual day to day cryptographic applications, and usually only employed when you are dealing with exceptional situations, like communication between a spy and the secret agency he/she works for...

the algorithm itself is well known ...

have a key that holds true for all assumptions above

bitwise xor with the plaintext

done

DarkSquirrel42
  • 10,167
  • 3
  • 20
  • 31