well, i started messing around with dictionaries, yet, most of the pages i found about them always talk about getting only one word out of it and turning it vice versa, i've been playing with that code for a few hours: -
#dics
-
Encryption={',':'hy{;',' ':'h4x0r2','':'zomg','?':'bko','a':'ika','b':'d0v','c':'ino', 'd':'maw', 'e':'aon', 'f':'que', 'g':'kip', 'h':'an[', 'i':'bf}', 'j':'ana&', 'k':'%d#', 'l':'d^f', 'm':'[d:w]', 'n':'ko[p', 'o':'{par:', 'p':'nt|;', 'q':'bz&$', 'r':'le{}', 's':'ak+', 't':'joq%', 'u':'f%(', 'v':'@!', 'w':'hg^*', 'x':'yu#', 'y':'fy%s', 'z':'mos@'}
-
Decryption=dict(zip(Encryption.values(), Encryption.keys()))
-
-
#functions#
-
-
-
-
# f1 enc #
-
def encrypt(x):
-
try:
-
#open spot for output#
-
lol=""
-
##
-
for letter in x:
-
lol += Encryption[letter]
-
print lol
-
except KeyError:
-
print 'These keys are not in the dictionary!'
-
-
-
# f2 dec #
-
def decrypt(y):
-
try:
-
lol=""
-
for mail in y:
-
lol += Decryption[mail]
-
print lol
-
except KeyError:
-
print 'These keys are not in the dictionary!'
-
-
#men#
-
def menu():
-
while 1:
-
t=raw_input('Do you want to Encrypt or to Decrypt?[e,d] ').lower()
-
#case 1#
-
#Enc#
-
while t=='e':
-
try:
-
print 'Enter Text below'
-
x=raw_input('').lower()
-
if len(x)<10:
-
print 'Print only long sentences'
-
-
else:
-
encrypt(x)
-
except KeyError:
-
print 'These keys are not in the dictionary!'
-
#case 2#
-
#Dec#
-
while t=='d':
-
try:
-
print 'Enter Text below'
-
y=raw_input('').lower()
-
decrypt(y)
-
except KeyError:
-
print 'These keys are not in the dictionary!'
-
#b2men#
-
menu()
-
-
trying to get an output from the reversed dictionary is just not working, keeps giving me KeyErrors, even i enter only 1 word that is IN the dictionary...
maybe it's because didn't use conventional letters, but still, how do i decrypt?
plz help
#Note: the Encryption works perfectly, the Decryption Doesn't.
I'm using python 2.5 (python 3 is weird O|o)
5 9473 bvdet 2,851
Expert Mod 2GB
You are iterating on the string in decrypt(). That means you are considering only one letter at a time. Try this instead: - def decrypt(y):
-
for key in Decryption:
-
if key in y:
-
while True:
-
try:
-
i = y.index(key)
-
y = y[:i]+Decryption[key]+y[i+len(key):]
-
except:
-
break
-
return y
Example: - >>> s = encrypt('temple of doom')
-
>>> s
-
'joq%aon[d:w]nt|;d^faonh4x0r2{par:queh4x0r2maw{par:{par:[d:w]'
-
>>> decrypt(s)
-
'temple of doom'
-
>>>
Oh, so this is how it's done...
the return is bugging it =/ changed it to print
bvdet 2,851
Expert Mod 2GB
Oh, so this is how it's done...
the return is bugging it =/ changed it to print
There probably is a better way to do it. :)
I generally prefer to return an object from a function then format the output as required. Using an IDE makes testing code much easier. In your case: - s = encrypt('temple of doom')
-
print s
-
print decrypt(s)
i need to decrypt binary, which example will work in that case?
is there a shortcut to create a Bin dictionary?
i need to decrypt binary, which example will work in that case?
is there a shortcut to create a Bin dictionary?
Oh never-mind, i got it working:D,
now i just need to enter all the uppercase letters and symbols into the dictionary :p
Sign in to post your reply or Sign up for a free account.
Similar topics
by: D. Alvarado |
last post by:
On my Fedora Core 2 Linux dev box, I have installed mcrypt and
compiled PHP with the --with-mcrypt option. I am concerned that when
I move to another hosting enviornment mcrypt will not be...
|
by: Jase H |
last post by:
Hello,
I have a ASP.NET web application problem involving the data encryption and
decryption assembly(DLL) used on the connection string value that is set in
the webconfig file.
The problem...
|
by: Robert Bull |
last post by:
I am looking for an example of encryption/decryption in asp.net. I
want to encrypt a string before I send it to a Web Service, decrypt it
on the Web Service then encrypt the results on the Web...
|
by: Mike |
last post by:
Hi,
I have been experimenting with the RijndaelManaged Cryptography class in C#
and have stumbled upon a "peculiarity".
Following code is standalone Console App that demonstrates
using...
|
by: almurph |
last post by:
Hi everyone,
Can you help me please? I am having a problem with the
encryption/decryption of words with the Irish fada in them. The Irish
fada is like this: áéíóú/ÁÉÍÓÚ. It's kind of like the...
|
by: tfoxusenet |
last post by:
Hi, I need to encrypt/decrypt some data for my C# application that can
also be read on a unix system, and need a quick, simple, cross-platform
solution I can embed in my own code that doesn't...
|
by: Mythran |
last post by:
I have googled and tested and tried and still I can't seem to implement a
simple encryption/decryption console application. My goal is to create two
methods.
public byte Encrypt(string...
|
by: ppuniversal |
last post by:
Hello,
I am making a DES encryption/decryption program using OpenSSL library.
I am using function
des_ecb_encrypt(des_cblock *input, des_cblock *output, des_cblock *keysched, int mode);
...
|
by: Dipanwita |
last post by:
I have written a RSA encryption/decryption function in c using the formula a = b^c %n. For solving the equation I have used Squaring and multiplying method for modulo exponentiation .
These...
|
by: =?Utf-8?B?TG9yZW4=?= |
last post by:
I’m trying to encrypt and decrypt a file in vb.net. I am using the
TripleDESCryptoServiceProvider encryption found in
System.Security.Cryptography. Below is the code for my Encrypt and Decrypt...
|
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: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |