From 6f526d20fc784ad444e576d17ec0eb3dce74e158 Mon Sep 17 00:00:00 2001 From: shivansh kumar <42717219+shivansh2310@users.noreply.github.com> Date: Sat, 5 Oct 2019 01:42:22 +0530 Subject: [PATCH 1/2] Binary Converter --- Binary-hex-octal-converter.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Binary-hex-octal-converter.c diff --git a/Binary-hex-octal-converter.c b/Binary-hex-octal-converter.c new file mode 100644 index 0000000..0611fd2 --- /dev/null +++ b/Binary-hex-octal-converter.c @@ -0,0 +1,34 @@ +#include +void convert(int, int); + +int main() +{ + int num; + printf("Enter a positive decimal number : "); + scanf("%d", &num); + printf("\nBinary number :: "); + convert(num, 2); + printf("\n"); + printf("\nOctal number :: "); + convert(num, 8); + printf("\n"); + printf("\nHexadecimal number :: "); + convert(num, 16); + printf("\n"); + + return 0; +} + +void convert (int num, int base) +{ + int rem = num%base; + + if(num==0) + return; + convert(num/base, base); + + if(rem < 10) + printf("%d", rem); + else + printf("%c", rem-10+'A' ); +} \ No newline at end of file From 2a813cd5dda22ea7c999de966152a6c1bb7de684 Mon Sep 17 00:00:00 2001 From: shivansh2310 Date: Mon, 5 Oct 2020 20:10:04 +0530 Subject: [PATCH 2/2] Hill Cipher implementation in python --- Crypto/hill_cipher.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Crypto/hill_cipher.py diff --git a/Crypto/hill_cipher.py b/Crypto/hill_cipher.py new file mode 100644 index 0000000..943c463 --- /dev/null +++ b/Crypto/hill_cipher.py @@ -0,0 +1,42 @@ +import numpy as np +s=list(input("Enter a string")) +c=[] +for i in range(len(s)): + c.append(ord(s[i])-65) + +arr= np.array(c) + +a1=np.transpose(arr) +print(a1) +a1= a1.reshape(3,1) +print(a1.shape) + + +#key input +print("Enter the key for the encryption") +R = int(input("rows:")) +C = int(input("columns:")) +matrix = [] +print("Enter the key:") + +for i in range(R): + a =[] + for j in range(C): + a.append(int(input())) + matrix.append(a) + +for i in range(R): + for j in range(C): + print(matrix[i][j], end = " ") +matrix = np.array(matrix) +print(matrix.shape) +print(matrix[1][1]) + +mul=np.matmul(matrix,a1) +mul = np.array(mul) +print(mul.shape) +print(mul) +for i in range(R): + mul[i]=mul[i]%26 + +print(mul)