Showing posts with label alphabet. Show all posts
Showing posts with label alphabet. Show all posts

Wednesday, February 15, 2012

[C++] Frequency Analysis (Alphabet)

          Hello, Reader ^^! Back again with source code ^^! This time the source code is Frequency Analysis for Alphabet. The source code written in C++. The source code can count how many N-Graph does a text have. It also the percentage of each N-Graph. Example:

> Input with Digraph (2-Graph):
"One day, I got a chicken lemper. However, when I ate it, it has no chicken meat.Where did the chicken go?"

> Output:

ON => 1 (2.5%)
ED => 1 (2.5%)
AY => 1 (2.5%)
IG => 1 (2.5%)
OT => 1 (2.5%)
AC => 1 (2.5%)
HI => 1 (2.5%)
CK => 1 (2.5%)
EN => 1 (2.5%)
LE => 1 (2.5%)
MP => 1 (2.5%)
ER => 1 (2.5%)
HO => 1 (2.5%)
WE => 1 (2.5%)
VE => 1 (2.5%)
RW => 1 (2.5%)
HE => 3 (7.5%)
NI => 1 (2.5%)
AT => 1 (2.5%)
EI => 1 (2.5%)
TI => 1 (2.5%)
TH => 1 (2.5%)
AS => 1 (2.5%)
NO => 1 (2.5%)
CH => 2 (5%)
IC => 2 (5%)
KE => 2 (5%)
NM => 1 (2.5%)
EA => 1 (2.5%)
TW => 1 (2.5%)
RE => 1 (2.5%)
DI => 1 (2.5%)
DT => 1 (2.5%)
NG => 1 (2.5%)
O? => 1 (2.5%)

As you can see, there is '?' there. That will ensure if there is some letters left which is not multiplied by N, then it will append '?' character. Okay, that's all I can say. Thank you for reading ^^!












Sunday, February 5, 2012

[Java] Vigenère Cipher (Alphabet)

          Hello, Reader ^^! Back again with source code ^^! This time the source code is Vigenère Cipher for Alphabet only. The source code written in Java. Yup, it is translated from C++ into Java ^^. With this type of encryption, the plaintext is encrypted based on key which consists of a keyword. Each letter will be ciphered differently based on the sequence of its letter on plaintext and the key. Let's take an example.

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



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


Using the Ci = (P+ Ki ) mod 26 (C is Ciphertext, P is Plaintext, K is Key, i is Index), it will give result :
"RIJVS GSPVH!"


With that type of encryption, cracking the message using frequency analysis can be prevented.


Now, I also made another variant. It is Auto-Key. Using the example above, the key will be "KEYHE LLOWO", taking some part of the plaintext as key. The result will be "AIDSS HZFHR!". Okay, that's all I can say ^^. Thank you for reading ^^!








Download/View Source Code





Thursday, February 2, 2012

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

          Hello, Reader ^^! Back again with source code ^^! This time the source code is Vigenère Cipher for Alphabet only. The source code written in C++. With this type of encryption, the plaintext is encrypted based on key which consists of a keyword. Each letter will be ciphered differently based on the sequence of its letter on plaintext and the key. Let's take an example. 

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


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

Using the Ci = (P+ Ki ) mod 26 (C is Ciphertext, P is Plaintext, K is Key, i is Index), it will give result :
"RIJVS GSPVH!"

With that type of encryption, cracking the message using frequency analysis can be prevented.

Now, I also made another variant. It is Auto-Key. Using the example above, the key will be "KEYHE LLOWO", taking some part of the plaintext as key. The result will be "AIDSS HZFHR!". Okay, that's all I can say ^^. Thank you for reading ^^!





Download/View Source Code
- Dropbox
- Dropbox (Repository)





Tuesday, January 31, 2012

[C++] Caesar Cipher (Alphabet)

          Hello, Reader ^^! Back again with source code ^^! This time the source code is Caesar Cipher for Alphabet only. The source code written in C++. This is a classic encryption method used by a caesar to send secret message. This application can encrypt plaintect into ciphertext using key and decrypt ciphertext using key and exhaustive search. Now, for some simple explanation. Just say I have word "Virucodesoup". I want to encrypt it. I use key = 10 which rotate letters by 10 which turns "Virucodesoup" into "FSBEMYNOCYEZ". Here's some formula of encryption: 

En(x) = (x + n) mod 26 [1]

From the example, if you put V, it will be rotated into F. For the decryption, here's some formula:

Dn(x) = (x - n) mod 26 [1]

From the example, if you put F, it will be rotated into V. Okay, that's all I can say. Thank you for reading ^^!





Extra Credit
-[1]Formula based on Wikipedia

Download/View Source Code
- Dropbox
- Dropbox (Repository)
- GitHub
- GitHub (Repository)





Thursday, January 26, 2012

[C++] Alphabet Soup (Facebook Hacker Cup 2012)

          Hello, Reader ^^! Back again with source code ^^! This time the source code is Alphabet Soup which is from Facebook Hacker Cup 2012. The source code is written in C++. This application can count how many HACKERCUP word can be made from H, A, C, K, E, R, U, and P letters which is obtained from input. I made this one when I competed in qualification round but didn't pass ( a small mistake, but fatal ). Oh well, rather I regret my time wasted making this code, I better posted it in here instead :). Okay, that's all I can say. Thank you for reading ^^!





Extra Credit:
- Problem case and example (in alphabet_soup.txt and alphabet_soup_example.txt) from Facebook Hacker Cup 2012 Qualification Round

Download/View Source Code:
- Dropbox
- Dropbox (Repository)
GitHub
- GitHub (Repository)