Saturday, February 4, 2012

[C++] Vigenère Cipher (ASCII)

          Hello, Reader ^^! Back again with source code ^^! This time the source code is Vigenère Cipher for ASCII. The source code written in C++. It is a bit different than the Alphabet version. This time the non-alphabet are also encrypted (for the alphabet version, non-alphabets are ignored). Okay, let me explain abit again but with ASCII version.

Just say I have plaintext "Hello World!". I want to encrypt it using key "KEY". If encrypt it using Vigenère Cipher, here will be happens:


Plaintext
H
E
L
L
O
W
O
R
L
D
!
Ciphertext
K
E
Y
K
E
Y
K
E
Y
K
E
Y


The key becomes "KEYKEYKEYKEY". Yup, it is repeated based on the length of the plaintext.


Using the Ci = (P+ Ki ) mod 256 (C is Ciphertext, P is Plaintext, K is Key, i is Index), it will give result :
"“Š¥—”y¢”«—‰z".


For the Auto-Key, it also uses ASCII range. Okay, that's all I can say. Thank you for reading ^^!







Download/View Source Code
- Dropbox





2 comments: