My program needs to fix an encrypted text file. The person who wrote it put it in “leet speak”, with special characters representing various letters. For example, consider the sample below:
1 4|-| 50 |_33+.
is really
I am so leet.
Here is the conversion table I need to use.
A 4
B 8
C [
D |)
E 3
F |#
G 6
H #
I 1
J ]
K |\
L |_
M |-|
N |\|
O 0
P |*
Q 0\
R 2
S 5
T +
U |_|
V \/
W \/\/
X ><
Y 7
Z 7_
Your program should read leet speak sentences from a file called "leet.txt" (one sentence per line). It should covert each sentence to normal English and print it to the screen.
here is what I have: -
d= {"4":"A", "8":"B", "[":"C", "|)":"D", "3":"E", "|#":"F", "6":"G", "#":"H", "1":"I", "]":"J", "|\\":"K", "|_":"L", "|-|":"M", "|\\|":"N", "0":"O", "|*":"P", "0\\":"Q", "2":"R", "5":"S", "+":"T", "|_|":"U", "\\/":"V", "\\/\\/":"W", "><":"X", "7":"Y", "7_":"Z"}
-
infile = open("leet.txt", "r")
-
for line in infile:
-
line.split
-
window = 4
-
i = 0
-
while i < len(line):
-
t = line[i:i+window]
-
i += window
-
print (line)
-
It is printing in leet but where do I put in the line to map it to the dictionary? And How do I move down?
4 4347
You look up each character in the dictionary http://www.java2s.com/Code/Python/Di...lternative.htm http://books.google.com/books?id=1Hx...ership&f=false. Of course, the character "|" and others signal a multiple character conversion, so for those characters you would have to test for 2 characters, then 3, etc. until a match is found. - d= {"4":"A", "8":"B", "[":"C", "|)":"D", "3":"E", "|#":"F", "6":"G", "#":"H", "1":"I", "]":"J", "|\\":"K", "|_":"L", "|-|":"M", "|\\|":"N", "0":"O", "|*":"P", "0\\":"Q", "2":"R", "5":"S", "+":"T", "|_|":"U", "\\/":"V", "\\/\\/":"W", "><":"X", "7":"Y", "7_":"Z"}
-
-
ch ='4'
-
print "%s translates to %s" % (ch, d[ch])
-
ch =']'
-
print "%s translates to %s" % (ch, d[ch])
We are supposed to start with 4 which is the longest character and work back to 1.
You will have to start with 4 characters and remove the right-most under a while() loop until it is found. Ask you instructor what happens if you have "O" followed by "V" or "W". How can you tell that it is not a "Q":
"OV" = 0\/ ## will find "Q" = "0\" going from 4 chars to one
"OW" = 0\/\/ ## will find "Q" = "0\"
"Q" = 0\
"O" = 0
Unless you copied the dictionary wrong. Changing "Q" to a forward slash, 0/ would fix it.
A very quick and dirty solution that hopefully will help you solve this for yourself. It does not allow for a malformed leet that is not found in the lookup dictionary, and probably other things as well, but that is up to you to do. - def from_leet(d, phrase, ctr):
-
to_add = 4
-
if ctr+to_add >= len(phrase):
-
to_add = len(phrase) - ctr
-
-
for x in range(to_add, 0, -1):
-
test_this = phrase_leet[ctr:ctr+x]
-
if test_this in d:
-
return(ctr+x, d[test_this])
-
return ctr, ""
-
-
def to_leet(d, phrase_in):
-
d_reverse = {}
-
for key in d:
-
d_reverse[d[key]] = key
-
phrase_in = phrase_in.upper()
-
output_list = []
-
for ch in phrase_in:
-
output_list.append(d_reverse[ch])
-
return("".join(output_list))
-
-
-
d= {"4":"A", "8":"B", "[":"C", "|)":"D", "3":"E", "|#":"F", "6":"G",
-
"#":"H", "1":"I", "]":"J", "|\\":"K", "|_":"L", "|-|":"M", "|\\|":"N",
-
"0":"O", "|*":"P", "0\\":"Q", "2":"R", "5":"S", "+":"T", "|_|":"U",
-
"\\/":"V", "\\/\\/":"W", "><":"X", "7":"Y", "7_":"Z"}
-
-
##phrase = "quickbrownfox" ## "ow" problem
-
phrase = "whydoesthecagedbirdsing"
-
phrase_leet = to_leet(d, phrase)
-
print phrase_leet, "\n"
-
-
ctr = 0
-
output_list = []
-
while ctr < len(phrase_leet):
-
ctr, letter = from_leet(d, phrase_leet, ctr)
-
output_list.append(letter)
-
-
print "".join(output_list)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Simon Wigzell |
last post by:
I recently wrote a program with MS Visual Studio C++, sent it off to the
client where it didn't run, after some probing I discover they are on a Mac!
My program is a MSF interface that is really...
|
by: simon lee |
last post by:
Dear all,
I use VC++ to write a program for display a flash file "file.fla", However,
for displaying flash file, it sometimes become black screen and sometimes
cannot display the corresponding...
|
by: Saurabh Saxena |
last post by:
can we write the program to write no 1 to n without using
switch,do,while,for,goto,if and conditional operator where n will be
input by user.
|
by: Tom |
last post by:
I am new to hardware programming.
I need to write a program for reading data from Card Reader which connects
to the PC windows 2000/XP OS through Interfacing The Serial / RS-232 Port /
USB /...
|
by: shaveta |
last post by:
The problem is like this:-
A maze is a rectangular area, with m rows and n columns, with an entrance and an exit. The interior of the maze contains obstacles. The entrance is at the upper-left...
|
by: shilkigupta |
last post by:
plz write a program to print
4
4 3 4
4 3 2 3 4
4 3 2 1 2 3 4
4 3 2 3 4
4 3 4
...
|
by: ASIM ABBAS |
last post by:
sri my questuon is that
write a program in corc++
to check wether a relation is equlance or not using two dimensional array
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |