Skip to content

Commit 18f198b

Browse files
authored
Merge pull request #110 from TowKnee0/my-branch
TowKnee0 | Scytale Cipher | new
2 parents a038ec5 + 5ebe7eb commit 18f198b

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

Scytale Cipher/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Scytale Cipher
2+
3+
Very basic implementation of the Scytale cipher.

Scytale Cipher/cipher.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
def encrypt(key, plaintext):
3+
4+
grid = []
5+
row = []
6+
7+
for letter in plaintext:
8+
row.append(letter)
9+
if len(row) == key:
10+
grid.append(row)
11+
row = []
12+
13+
text = []
14+
15+
for col in range(key):
16+
temp = []
17+
for row in grid:
18+
temp.append(row[col])
19+
text.append(str.join('', temp))
20+
21+
return str.join('', text)
22+
23+
24+
def decrypt(key, ciphertext):
25+
26+
rows = len(ciphertext) // key
27+
grid = []
28+
29+
for row in range(rows):
30+
temp_row = []
31+
for i in range(key):
32+
temp_row.append(ciphertext[row + i * rows])
33+
grid.append(temp_row)
34+
35+
rows = []
36+
37+
for i in range(len(grid)):
38+
rows.append(str.join('', grid[i]))
39+
40+
return str.join('', rows)

0 commit comments

Comments
 (0)