I am trying to write code to implement the vernam cipher in C++, but my code does not run. I don't know what the problem is. The code will get message in zero, one, and key also, and then implement XOR of them to create the cipher text and the same of decrypt method, when I run it it's get me a warnning and stop the run .
Vernam Cipher, a perfect cipher As introduction to stream ciphers, and to demonstrate that a perfect cipher does exist, we describe the Vernam Cipher, also known as the one-time-pad. Gilbert Vernam invented and patented his cipher in 1917 while working at AT&T. The teletype had been recently introduced, and along with this the commerical Baudot code. Apr 27, 2017 The vernam cipher algorithm in python enlisted here is really strong in terms of hacks or loopholes just because the algorithm itself is very strong. Must Read: Caesar Cipher Encryption Algorithm C Program. Gilbert Vernam proposed a bit-wise exclusive OR of the stream with a random zero-one stream which is shared by the recipient and the sender.
vsoftco43.4k55 gold badges8585 silver badges182182 bronze badges
Rawan MansourRawan Mansour
1 Answer
In the
encrypt()
function, try this:Otherwise you're using the ASCII codes of the characters. Also, modify the loop so that it uses
<
, not <=
.And modify the return type of
vsoftcovsoftcomain()
to int
, this is C++.43.4k55 gold badges8585 silver badges182182 bronze badges
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Not the answer you're looking for? Browse other questions tagged c++ or ask your own question.
I want to learn vernam encryption.
First of all, can you confirm me that the algorithm is the same for encoding and decoding?
I have read an exercice which say to decode this message with Pi:
I have tried vernam python pacakge and i tried this:
or
But it does not give me a readable message...
Thanks
![Commercial encryption algorithms Commercial encryption algorithms](/uploads/1/2/5/2/125263522/858488270.png)
24.7k88 gold badges6363 silver badges7474 bronze badges
Bob5421Bob54211,51733 gold badges2424 silver badges6262 bronze badges
1 Answer
'can you confirm me that the algorithm is the same for encoding and decoding?'
-> first of all, we are talking about encryption not encoding (at the first step) ... the notable difference, to tell those two apart, is that there is a key involved here...
depending on which variant of vernam you are handling, encryption and decryption may be the same or not ... for the binary variant it surely is the same operation, a simple XOR
if you happen to have got your fingers on the 'let's do this by hand' or schoolbok variant, it is not, basically because it handles values mod 10 and not mod 2, leading to encryption is + ... decryption is - ...
the notation in blocks of 5 is an indication for the mod 10 variant, since with the mod 2 variant you usually just handle binary data
so finally we have to read the encoding into characters... (second step)
![Algorithm Algorithm](/uploads/1/2/5/2/125263522/709760084.jpg)
it is up to the user of the cipher to give these numbers a meaning so when searching for your example message you can find a french page showing a substitution table... so ... let's have a look ...
Substitution table:
Result:
DarkSquirrel42DarkSquirrel428,12222 gold badges1515 silver badges2525 bronze badges
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.