Showing posts with label cipher. Show all posts
Showing posts with label cipher. Show all posts

Thursday, March 22, 2012

[C#] CFB (Cipher Feedback)

          Hello, Reader ^^! Back again with source code. This time is is CFB (Cipher Feedback) which is made using C# programming language. This one, like CBC, also encrypts block per block from previous blocks. The first block uses Initialization Vector. The IV (and the next xor-ed plaintext and Encryption Block), will be encrypted into Encryption Block. After that, it will xor-ed with plaintext which will be the ciphertext. A mistake just a bit can lead mistake also in the encryption and decryption. The Encryption Block used in this example is the simple XOR. You can define your own Encryption Block like doing shift left, shift right, etc. Now, let me demonstrate a bit:

plain text (in bit) : 0101111111010101
key : 10101
IV generated 10001
Encryption Block = a xor b

Now, splitting them into 5 blocks (based on key's length): 01011|11111|01010|1
The last part length is not 5, so let's padding it with 0 bits : 10000




IV(only 1st block), then from the Fifth row 10001 10001 11011 01110 
Key01011 10101 11111 00000 
Encryption Block (a xor b; a is first row, b is key) 11010001000010001110
Plaintext (in bits)
01011 11111 01010 10000
Xor-ed (Plaintext with third row)  
10001110110111011111


The result of encryption is 10001110110111011111. If you see at the 3rd column, at the 2nd row, you will see the value is taken from 2nd column, 5th row. Yup, that's why it is chaining.

Okay, that's all I can say. Thank you for reading ^^!


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





[C#] CBC (Cipher-Block Chaining)

          Hello, Reader ^^! Back again with source code. This time is is CBC (Cipher-Block Chaining) which is made using C# programming language. This one, uses encryption per block which came from the previous block. This way, the encryption becomes stronger, not only that, with Initialization Vector which is generated random, it made encryption more unique even with the same key. The IV can be kept or not, because when decryption, it won't effect the other block not like when enciphering. The Encryption Block used in this example is the simple XOR. You can define your own Encryption Block like doing shift left, shift right, etc. Now, let me demonstrate a bit:

plain text (in bit) : 0101111111010101
key : 10101
IV generated 10001
Encryption Block = a xor b

Now, splitting them into 5 blocks (based on key's length): 01011|11111|01010|1
The last part length is not 5, so let's padding it with 0 bits : 10000





Plaintext(in bits)01011111110101010000
IV(only 1st block), then from the Encryption Block 01011 10101 11111 00000 
Xor-ed (Plaintext with second row)00000010101010110000 
Key1010110101 10101 10101 
Encryption Block (a xor b; a is xor-ed bits, b is key)10101111110000000101


The result of encryption is 10101111110000000101. If you see at the 3rd column, at the 2nd row, you will see the value is taken from 2nd column, 5th row. Yup, that's why it is chaining.

One more thing, it also can encrypt and decrypt file like the other block cipher mode :D (I forgot to mention it with toher block cipher mode). Okay, that's all I can say. Thank you for reading ^^!



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





Monday, March 19, 2012

[Ruby] Rail Fence Cipher Extended

          Hello, Reader ^^! Back again with source code. This time is a  Rail Fence Cipher Extended which is made from Ruby programming language. This one is a bit difficult and tricky. The formula needed is also tricky. The coding of encryption is easier than the decryption. The difference with the normal version is that the Extended version also accept non-number and non-alphabet character. The alphaber is case-sensitive in this version. Now for a bit of demonstration:


Take a string "Hello World!" 
Don't remove any character unlike the non-extended version.


Now, let's arrange them like this:


H   o   r
 e l   o l !
  l   w   d


Now, based on its arranged form, from left to right and below, it is turned into HOLELWRDLO as the encryption result. That's how the Rail Fence Cipher do.


Okay, that's all I can say. Thank you for reading ^^!


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





Saturday, March 17, 2012

[Ruby] CFB (Cipher Feedback)

          Hello, Reader ^^! Back again with source code. This time is is CFB (Cipher Feedback) which is made using Ruby programming language. This one, like CBC, also encrypts block per block from previous blocks. The first block uses Initialization Vector. The IV (and the next xor-ed plaintext and Encryption Block), will be encrypted into Encryption Block. After that, it will xor-ed with plaintext which will be the ciphertext. A mistake just a bit can lead mistake also in the encryption and decryption. The Encryption Block used in this example is the simple XOR. You can define your own Encryption Block like doing shift left, shift right, etc. Now, let me demonstrate a bit:

plain text (in bit) : 0101111111010101
key : 10101
IV generated 10001
Encryption Block = a xor b

Now, splitting them into 5 blocks (based on key's length): 01011|11111|01010|1
The last part length is not 5, so let's padding it with 0 bits : 10000







IV(only 1st block), then from the Fifth row 10001 10001 11011 01110 
Key01011 10101 11111 00000 
Encryption Block (a xor b; a is first row, b is key) 11010001000010001110
Plaintext (in bits)
01011 11111 01010 10000
Xor-ed (Plaintext with third row)  
10001110110111011111


The result of encryption is 10001110110111011111. If you see at the 3rd column, at the 2nd row, you will see the value is taken from 2nd column, 5th row. Yup, that's why it is chaining.

Okay, that's all I can say. Thank you for reading ^^!


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





[Ruby] CBC (Cipher-Block Chaining)

          Hello, Reader ^^! Back again with source code. This time is is CBC (Cipher-Block Chaining) which is made using Ruby programming language. This one, uses encryption per block which came from the previous block. This way, the encryption becomes stronger, not only that, with Initialization Vector which is generated random, it made encryption more unique even with the same key. The IV can be kept or not, because when decryption, it won't effect the other block not like when enciphering. The Encryption Block used in this example is the simple XOR. You can define your own Encryption Block like doing shift left, shift right, etc. Now, let me demonstrate a bit:

plain text (in bit) : 0101111111010101
key : 10101
IV generated 10001
Encryption Block = a xor b

Now, splitting them into 5 blocks (based on key's length): 01011|11111|01010|1
The last part length is not 5, so let's padding it with 0 bits : 10000





Plaintext(in bits)01011111110101010000
IV(only 1st block), then from the Encryption Block 01011 10101 11111 00000 
Xor-ed (Plaintext with second row)00000010101010110000 
Key1010110101 10101 10101 
Encryption Block (a xor b; a is xor-ed bits, b is key)10101111110000000101


The result of encryption is 10101111110000000101. If you see at the 3rd column, at the 2nd row, you will see the value is taken from 2nd column, 5th row. Yup, that's why it is chaining.

Okay, that's all I can say. Thank you for reading ^^!


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





Thursday, March 15, 2012

[Ruby] Rail Fence Cipher

          Hello, Reader ^^! Back again with source code. This time is a  Rail Fence Cipher which is made from Ruby programming language. This one is a bit difficult and tricky. The formula needed is also tricky. The coding of encryption is easier than the decryption. Now for a bit of demonstration:


Take a string "Hello World!"
Remove all non-number and non-alphabet. Uppercase all of the string. Remove all the space. The result:
"HELLOWORLD"


Now, let's arrange them like this:


H   O   L
 E L W R D
  L   O


Now, based on its arranged form, from left to right and below, it is turned into HOLELWRDLO as the encryption result. That's how the Rail Fence Cipher do.


Okay, that's all I can say. Thank you for reading ^^!


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





Monday, February 6, 2012

[Java] 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 Java, translated from C++ version. 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 :
"³Êå×Ô™ÂÔë×Éš".


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







Download/View Source Code






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





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





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)





Wednesday, February 1, 2012

[C++] Caesar Cipher (ASCII)

          Hello, Reader ^^! Back again with source code ^^! This time the source code is Caesar Cipher for ASCII. How it works it is still same with the Alphabet version. The only differences are this time it is not limited to alphabet anymore, but it is ASCII. Plus, the effective key is increased to 256 keys. Plus, with that, the formula for encryption is:

En(x) = (x + n) mod 256

While the formula for decryption is:

Dn(x) = (x - n) mod 256

For example, I use "HeLLo WoRlD!". I encrypt it with key = 122. It will be rotated into "Â߯ÆéšÑéÌæ¾›". Okay, that's all I can say ^^! Thank you for reading ^^!





Download/View Source Code
- Dropbox
Dropbox (Repository)
- GitHub
- GitHub (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)