This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Program to calculate Hashing using Mid Square method | |
Created by: Dr. Ajit Kumar | |
Email: ajitkumar.pu@gmail.com | |
Date: 8-04-2019 | |
*/ | |
#include<stdio.h> | |
#include<string.h> | |
#include <math.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<string.h> | |
#include <math.h> | |
int count_digits(int key) | |
{ | |
int count=0; | |
while(key != 0) | |
{ | |
key /= 10; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int multiplication_method(int k, int m) | |
{ | |
int const A = 0.6180339887; | |
return floor(m * (k*A - floor(k*A))); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
int division_method(int x, int m) | |
{ | |
return x % m; | |
} | |
void main() | |
{ | |
int const m = 7; | |
int x = 25; | |
int hash_value=0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
M = '0123456789ABCDEF' | |
key ='12345678ABCEDFF9' | |
def DES_encrypt(message,key): | |
cipher = "" | |
# Convert hex digits to binary | |
plaintext_bits = hexTobinary(message) | |
key_bits = hexTobinary(key) | |
# Generate rounds key | |
roundkeys = generate_keys(key_bits) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def XOR(bits1,bits2): | |
xor_result = "" | |
for index in range(len(bits1)): | |
if bits1[index] == bits2[index]: | |
xor_result += '0' | |
else: | |
xor_result += '1' | |
return xor_result | |
# Generate round keys Part- 1 of blog post |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INVERSE_PERMUTATION_TABLE = ['40 ', '8 ', '48 ', '16 ', '56 ', '24 ', '64 ', '32', | |
'39 ', '7 ', '47 ', '15 ', '55 ', '23 ', '63 ', '31', | |
'38 ', '6 ', '46 ', '14 ', '54 ', '22 ', '62 ', '30', | |
'37 ', '5 ', '45 ', '13 ', '53 ', '21 ', '61 ', '29', | |
'36 ', '4 ', '44 ', '12 ', '52 ', '20 ', '60 ', '28', | |
'35 ', '3 ', '43 ', '11 ', '51 ', '19 ', '59 ', '27', | |
'34 ', '2 ', '42 ', '10 ', '50 ', '18 ', '58 ', '26', | |
'33 ', '1 ', '41 ', '9 ', '49 ', '17 ', '57 ', '25'] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
M = '0123456789ABCDEF' | |
plaintext = hexTobinary(M) | |
print plaintext | |
p_plaintext = apply_initial_p(INITIAL_PERMUTATION_TABLE,plaintext) | |
print p_plaintext | |
## output: | |
# 0000000100100011010001010110011110001001101010111100110111101111 | |
# 1100110000000000110011001111111111110000101010101111000010101010 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def hexTobinary(hexdigits): | |
binarydigits = "" | |
for hexdigit in hexdigits: | |
binarydigits += bin(int(hexdigit,16))[2:].zfill(4) | |
return binarydigits | |
INITIAL_PERMUTATION_TABLE = ['58 ', '50 ', '42 ', '34 ', '26 ', '18 ', '10 ', '2', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HEX_to_Binary = {'0':'0000', | |
'1':'0001', | |
'2':'0010', | |
'3':'0011', | |
'4':'0100', | |
'5':'0101', | |
'6':'0110', | |
'7':'0111', | |
'8':'1000', | |
'9':'1001', |