|
Cryptography
1.0
Implementation of Cryptography Algorithms
|
Functions | |
| def | binary_string (k) |
| BINARY STRING COVERSION. More... | |
| def | get_x_bit_permutation (k, pc) |
| GET PERMUTATION STRING. More... | |
| def | perform_xor (first_d, second_d) |
| def | compression_to_32 (string) |
| GET PERMUTATION STRING. More... | |
Variables | |
| list | EXPANSION |
| This is an implementation of DES Cipher Algorithm DES = Data Encryption Standard STEP 1: create all constants first. More... | |
| list | IP |
| IP = Initial Permutation This is used to permute the plain_text binary form based on the beloe stated table. More... | |
| list | PC1 |
| PC1 = Permuted Choice 1 This is used to permute the plain_text binary form based on the below stated table. More... | |
| list | PC2 |
| PC2 = Permuted Choice 2 This is used to permute the plain_text binary form based on the below stated table. More... | |
| list | LEFTROTS |
| list | S |
| S-Boxes We now do something strange with each group of six bits: we use them as addresses in tables called "S boxes". More... | |
| list | Reduced_ka_permutation |
| int | hexa_scale = 16 |
| key = str(input()) | |
| plaintext = str(input()) | |
| L = plaintext[0:8] | |
| R = plaintext[8:16] | |
| plain_binary = binary_string(plaintext) | |
| b_key = binary_string(key) | |
| five_six_perm = get_x_bit_permutation(b_key, PC1) | |
| list | C = [] |
| list | D = [] |
| first = C[i - 1][0] | |
| second = D[i - 1][0] | |
| Cx = C[i - 1][1:28]+first | |
| Dx = D[i - 1][1:28]+second | |
| list | key_list = [] |
| list | hex_key_list = [] |
| initial_permutation = get_x_bit_permutation(plain_binary, IP) | |
| L0 = initial_permutation[0:32] | |
| R0 = initial_permutation[32:64] | |
| L1 = copy(R0) | |
| ER0 = get_x_bit_permutation(R0, EXPANSION) | |
| func_ER0K1 = perform_xor(key_list[0], ER0) | |
| reduced_value = compression_to_32(func_ER0K1) | |
| permuted_reduced_val = get_x_bit_permutation(reduced_value, Reduced_ka_permutation) | |
| R1 = perform_xor(L0, permuted_reduced_val) | |
| final_bit_string = L1+R1 | |
| final_res = hex(int(final_bit_string, 2))[2:].upper() | |
@package DESKeygen Documentation for this module.
| def DESKeygen.binary_string | ( | k | ) |
BINARY STRING COVERSION.
| k | hexanumber This basically returns a string of 64 bits to the caller |
| def DESKeygen.compression_to_32 | ( | string | ) |
GET PERMUTATION STRING.
| string | the 48-bit key Returns a compressed string of 32-bits using the S-boxes |
| def DESKeygen.get_x_bit_permutation | ( | k, | |
| pc | |||
| ) |
GET PERMUTATION STRING.
| k | hexanumber |
| pc | Permutation Array This basically returns a string formed by the PC array using permutation bits |
| def DESKeygen.perform_xor | ( | first_d, | |
| second_d | |||
| ) |
| DESKeygen.b_key = binary_string(key) |
| list DESKeygen.C = [] |
| list DESKeygen.D = [] |
| DESKeygen.ER0 = get_x_bit_permutation(R0, EXPANSION) |
| list DESKeygen.EXPANSION |
This is an implementation of DES Cipher Algorithm DES = Data Encryption Standard STEP 1: create all constants first.
The follow lists are values used for encryption
| DESKeygen.final_res = hex(int(final_bit_string, 2))[2:].upper() |
| DESKeygen.first = C[i - 1][0] |
| DESKeygen.five_six_perm = get_x_bit_permutation(b_key, PC1) |
| DESKeygen.func_ER0K1 = perform_xor(key_list[0], ER0) |
| list DESKeygen.hex_key_list = [] |
| int DESKeygen.hexa_scale = 16 |
| DESKeygen.initial_permutation = get_x_bit_permutation(plain_binary, IP) |
| list DESKeygen.IP |
IP = Initial Permutation This is used to permute the plain_text binary form based on the beloe stated table.
| DESKeygen.key = str(input()) |
| list DESKeygen.key_list = [] |
| DESKeygen.L = plaintext[0:8] |
| DESKeygen.L0 = initial_permutation[0:32] |
| DESKeygen.L1 = copy(R0) |
| list DESKeygen.LEFTROTS |
| list DESKeygen.PC1 |
PC1 = Permuted Choice 1 This is used to permute the plain_text binary form based on the below stated table.
Basically PC1 converts the 64 bits key to 56 bit and values at 8th, 16th bits and soon are removed
| list DESKeygen.PC2 |
PC2 = Permuted Choice 2 This is used to permute the plain_text binary form based on the below stated table.
Basically PC1 converts the 56 bits key to 48 bit.
| DESKeygen.permuted_reduced_val = get_x_bit_permutation(reduced_value, Reduced_ka_permutation) |
| DESKeygen.plain_binary = binary_string(plaintext) |
| DESKeygen.plaintext = str(input()) |
| DESKeygen.R = plaintext[8:16] |
| DESKeygen.R0 = initial_permutation[32:64] |
| DESKeygen.R1 = perform_xor(L0, permuted_reduced_val) |
| list DESKeygen.Reduced_ka_permutation |
| DESKeygen.reduced_value = compression_to_32(func_ER0K1) |
| list DESKeygen.S |
S-Boxes We now do something strange with each group of six bits: we use them as addresses in tables called "S boxes".
Each group of six bits will give us an address in a different S box. Located at that address will be a 4 bit number. This 4 bit number will replace the original 6 bits. The net result is that the eight groups of 6 bits are transformed into eight groups of 4 bits (the 4-bit outputs from the S boxes) for 32 bits total.
| DESKeygen.second = D[i - 1][0] |
1.8.11