tangled
alpha
login
or
join now
thecoded.prof
/
CMU
0
fork
atom
CMU Coding Bootcamp
0
fork
atom
overview
issues
pulls
pipelines
fix: small name fixes
thecoded.prof
5 months ago
81e279d8
2ab905d9
verified
This commit was signed with the committer's
known signature
.
thecoded.prof
SSH Key Fingerprint:
SHA256:ePn0u8NlJyz3J4Zl9MHOYW3f4XKoi5K1I4j53bwpG0U=
+6
-6
1 changed file
expand all
collapse all
unified
split
python
oct2
level4
routeCipher2.py
+6
-6
python/oct2/level4/routeCipher2.py
···
1
1
from math import ceil
2
2
3
3
4
4
-
def f(row: int, col: int, rows: int) -> int:
4
4
+
def getIndex(row: int, col: int, rows: int) -> int:
5
5
return col*rows + row
6
6
7
7
8
8
-
def i_f(x: int, rows: int) -> tuple[int, int]:
8
8
+
def getRowAndCol(x: int, rows: int) -> tuple[int, int]:
9
9
return x // rows, x % rows
10
10
11
11
···
17
17
cur_char = chr(ord(cur_char) - 1)
18
18
encoded_string = ""
19
19
for i in range(len(message)):
20
20
-
row, col = i_f(i, row_len)
21
21
-
encoded_string += message[f(row, col, rows)]
20
20
+
row, col = getRowAndCol(i, row_len)
21
21
+
encoded_string += message[getIndex(row, col, rows)]
22
22
encoded_message = f"{rows}"
23
23
for i in range(0, rows):
24
24
if i % 2 == 0:
···
40
40
else:
41
41
decoded_string += encoded_string[i*row_len:(i+1)*row_len][::-1]
42
42
for i in range(len(decoded_string)):
43
43
-
row, col = i_f(i, rows)
44
44
-
decoded_message += decoded_string[f(row, col, row_len)]
43
43
+
row, col = getRowAndCol(i, rows)
44
44
+
decoded_message += decoded_string[getIndex(row, col, row_len)]
45
45
while decoded_message[-1].islower():
46
46
decoded_message = decoded_message[:-1]
47
47
return decoded_message