Hello, Reader ^^! Back again with source code. This time is String Replacer which is made using C# programming language. This shows how to do a string replace. Mainly, you can use (String object).Replace to replace the string. In this one, I also added save and load feature so it easier to read very long string. Okay, that's all I can say. Thank you for reading ^^!
Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts
Monday, June 4, 2012
Sunday, April 15, 2012
[C#] If-Then-Else Syntax
Hello, Reader ^^! Back again with source code. This time is a basic syntax If-Then-Else in C# programming language. This source code is to show how to do If-Then-Else statement in C# language. Here's the template:
if <condition> {
<statement if true>
} else {
<statement if false>
}
Okay, that's all I can say. Thank you for reading ^^!
<statement if true>
} else {
<statement if false>
}
Okay, that's all I can say. Thank you for reading ^^!
[C#] If-Then Syntax
Hello, Reader ^^! Back again with source code. This time is a basic syntax If-Then in C# programming language. This source code is to show how to do If-Then statement in C# language. Here's the template:
if <condition> {
<statement if true>
}
Okay, that's all I can say. Thank you for reading ^^!
<statement if true>
}
Okay, that's all I can say. Thank you for reading ^^!
Friday, March 23, 2012
[C#] OFB (Output Feedback)
Hello, Reader ^^! Back again with source code. This time is is OFB (Output Feedback) which is made using C# programming language. This one, like CFB, also encrypts block per block from previous blocks. The first block came from Initialization Vector. The difference is the OFB uses Encryption Block from previous Encryption Block. 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 Third row | 10001 | 00100 | 10001 | 00100 |
| Key | 10101 | 10101 | 10101 | 10101 |
| Encryption Block (a xor b; a is IV, b is key) | 00100 | 10001 | 00100 | 10001 |
| Plaintext (in bits) | 01011 | 11111 | 01010 | 10000 |
| Xor-ed (Plaintext with third row) | 01111 | 01110 | 01110 | 00001 |
The result of encryption is 01111011100111000001.
Okay, that's all I can say. Thank you for reading ^^!
[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 |
| Key | 01011 | 10101 | 11111 | 00000 |
| Encryption Block (a xor b; a is first row, b is key) | 11010 | 00100 | 00100 | 01110 |
| Plaintext (in bits) | 01011 | 11111 | 01010 | 10000 |
| Xor-ed (Plaintext with third row) | 10001 | 11011 | 01110 | 11111 |
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 ^^!
[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) | 01011 | 11111 | 01010 | 10000 |
| IV(only 1st block), then from the Encryption Block | 01011 | 10101 | 11111 | 00000 |
| Xor-ed (Plaintext with second row) | 00000 | 01010 | 10101 | 10000 |
| Key | 10101 | 10101 | 10101 | 10101 |
| Encryption Block (a xor b; a is xor-ed bits, b is key) | 10101 | 11111 | 00000 | 00101 |
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 ^^!
Wednesday, March 21, 2012
[C#] ECB (Electronic Code Book)
Hello, Reader ^^! Back again with source code. This time is is ECB (Electronic Code Book) which is made using C# programming language. There was a problem making it when facing the Unicode conversion to Binary and vice versa, but finally, it is solved :3. Now, Let me explain it again like the C++ before. Encryption using ECB is separating plaintext bit into blocks (key). After that, each block each encrypted with the block key. When the plaintext's length is not divideable by the key's length, pad it with all 0s or all 1s or 101010... In this example, the Encryption Block used is a simple xor. You can define your own Encryption Block. Now, let's me demonstrate a bit:
plain text (in bit) : 0101111111010101
key : 01101
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) | 01011 | 11111 | 01010 | 10000 |
| Key per block | 01011 | 01011 | 01011 | 01011 |
| Encryption Block (a xor b; a is Plaintext, b is key) | 00000 | 10100 | 00001 | 11011 |
The result of encryption is 00000101000000111011
Okay, that's all I can say. Thank you for reading ^^!
Subscribe to:
Posts (Atom)