forked from AllAlgorithms/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHill_cipher.py
More file actions
42 lines (34 loc) · 731 Bytes
/
Copy pathHill_cipher.py
File metadata and controls
42 lines (34 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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)