Skip to content

Commit

Permalink
Challenge 02 - solved
Browse files Browse the repository at this point in the history
  • Loading branch information
coral2742 committed Nov 24, 2022
1 parent a082c86 commit 20b2408
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions challenge02/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import re

def traduce (wordinASCII):
word = wordinASCII
# Puede haber dos casos:
# ASCII formado por dos dígitos
# a -> 97
# b -> 98
# c -> 99
# ASCII formado por tres dígitos
result = ""
while (word != ""):
# Comprobamos que empieza por 9
if (word[:1] == "9"):
# Separar los dos primeros
result += chr(int(word[:2]))
#print(chr(int(word[:2])))
word = word[2:]
else:
# Separar los tres primeros
#print(chr(int(word[:3])))
result += chr(int(word[:3]))
#print(chr(int(word[:3])))
word = word[3:]
return result

finalMessage = ""

with open("encrypted.txt", "r") as f:
file = f.readlines()

for line in range (len(file)):
message = (file[line].split())
for word in message:
finalMessage += traduce(word) + " "

print(finalMessage)

0 comments on commit 20b2408

Please sign in to comment.