Skip to content

Instantly share code, notes, and snippets.

View urwithajit9's full-sized avatar
🎯
Focusing on Blending AI & ML for Cyber Security and Malware Research

Ajit Kumar urwithajit9

🎯
Focusing on Blending AI & ML for Cyber Security and Malware Research
View GitHub Profile
/*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>
#include<stdio.h>
#include<string.h>
#include <math.h>
int count_digits(int key)
{
int count=0;
while(key != 0)
{
key /= 10;
int multiplication_method(int k, int m)
{
int const A = 0.6180339887;
return floor(m * (k*A - floor(k*A)));
}
#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;
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)
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
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']
M = '0123456789ABCDEF'
plaintext = hexTobinary(M)
print plaintext
p_plaintext = apply_initial_p(INITIAL_PERMUTATION_TABLE,plaintext)
print p_plaintext
## output:
# 0000000100100011010001010110011110001001101010111100110111101111
# 1100110000000000110011001111111111110000101010101111000010101010
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',
HEX_to_Binary = {'0':'0000',
'1':'0001',
'2':'0010',
'3':'0011',
'4':'0100',
'5':'0101',
'6':'0110',
'7':'0111',
'8':'1000',
'9':'1001',