tangled
alpha
login
or
join now
thecoded.prof
/
CMU
0
fork
atom
CMU Coding Bootcamp
0
fork
atom
overview
issues
pulls
pipelines
format
thecoded.prof
5 months ago
e81c3da0
2a8e0ff2
verified
This commit was signed with the committer's
known signature
.
thecoded.prof
SSH Key Fingerprint:
SHA256:ePn0u8NlJyz3J4Zl9MHOYW3f4XKoi5K1I4j53bwpG0U=
+6
-5
1 changed file
expand all
collapse all
unified
split
python
oct2
level4
routeCipher2.py
+6
-5
python/oct2/level4/routeCipher2.py
···
1
1
from math import ceil
2
2
from string import ascii_lowercase
3
3
4
4
+
4
5
def getIndex(row: int, col: int, rows: int) -> int:
5
5
-
return col*rows + row
6
6
+
return col * rows + row
6
7
7
8
8
9
def getRowAndCol(x: int, rows: int) -> tuple[int, int]:
···
20
21
encoded_message = f"{rows}"
21
22
for i in range(0, rows):
22
23
if i % 2 == 0:
23
23
-
encoded_message += encoded_string[i*row_len:(i+1)*row_len]
24
24
+
encoded_message += encoded_string[i * row_len : (i + 1) * row_len]
24
25
else:
25
25
-
encoded_message += encoded_string[i*row_len:(i+1)*row_len][::-1]
26
26
+
encoded_message += encoded_string[i * row_len : (i + 1) * row_len][::-1]
26
27
return encoded_message
27
28
28
29
···
34
35
decoded_string = ""
35
36
for i in range(rows):
36
37
if i % 2 == 0:
37
37
-
decoded_string += encoded_string[i*row_len:(i+1)*row_len]
38
38
+
decoded_string += encoded_string[i * row_len : (i + 1) * row_len]
38
39
else:
39
39
-
decoded_string += encoded_string[i*row_len:(i+1)*row_len][::-1]
40
40
+
decoded_string += encoded_string[i * row_len : (i + 1) * row_len][::-1]
40
41
for i in range(len(decoded_string)):
41
42
row, col = getRowAndCol(i, rows)
42
43
decoded_message += decoded_string[getIndex(row, col, row_len)]