473,748 Members | 4,065 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Encryption and Decryption from a dictionary.

58 New Member
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:
Expand|Select|Wrap|Line Numbers
  1. #dics
  2. 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@'}
  3. Decryption=dict(zip(Encryption.values(), Encryption.keys()))
  4.  
  5. #functions#
  6.  
  7.  
  8.  
  9. # f1 enc #
  10. def encrypt(x):
  11.     try:
  12.         #open spot for output#
  13.         lol=""
  14.         ##
  15.         for letter in x:
  16.             lol += Encryption[letter]
  17.         print lol
  18.     except KeyError:
  19.             print 'These keys are not in the dictionary!'
  20.  
  21.  
  22. # f2 dec #
  23. def decrypt(y):
  24.     try:
  25.         lol=""
  26.         for mail in y:
  27.             lol += Decryption[mail]
  28.         print lol
  29.     except KeyError:
  30.         print 'These keys are not in the dictionary!'
  31.  
  32. #men#
  33. def menu():
  34.     while 1:
  35.         t=raw_input('Do you want to Encrypt or to Decrypt?[e,d] ').lower()
  36. #case 1#
  37. #Enc#
  38.         while t=='e':
  39.             try:
  40.                 print 'Enter Text below'
  41.                 x=raw_input('').lower()
  42.                 if len(x)<10:
  43.                     print 'Print only long sentences' 
  44.  
  45.                 else:
  46.                     encrypt(x)
  47.             except KeyError:
  48.                 print 'These keys are not in the dictionary!'
  49. #case 2#
  50. #Dec#
  51.         while t=='d':
  52.             try:
  53.                 print 'Enter Text below'
  54.                 y=raw_input('').lower()
  55.                 decrypt(y)
  56.             except KeyError:
  57.                 print 'These keys are not in the dictionary!'
  58. #b2men#
  59. menu()
  60.  
  61.  
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)
Sep 30 '08 #1
5 9527
bvdet
2,851 Recognized Expert Moderator Specialist
You are iterating on the string in decrypt(). That means you are considering only one letter at a time. Try this instead:
Expand|Select|Wrap|Line Numbers
  1. def decrypt(y):
  2.     for key in Decryption:
  3.         if key in y:
  4.             while True:
  5.                 try:
  6.                     i = y.index(key)
  7.                     y = y[:i]+Decryption[key]+y[i+len(key):]
  8.                 except:
  9.                     break
  10.     return y
Example:
Expand|Select|Wrap|Line Numbers
  1. >>> s = encrypt('temple of doom')
  2. >>> s
  3. 'joq%aon[d:w]nt|;d^faonh4x0r2{par:queh4x0r2maw{par:{par:[d:w]'
  4. >>> decrypt(s)
  5. 'temple of doom'
  6. >>> 
Sep 30 '08 #2
Netwatcher
58 New Member
Oh, so this is how it's done...
the return is bugging it =/ changed it to print
Sep 30 '08 #3
bvdet
2,851 Recognized Expert Moderator Specialist
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:
Expand|Select|Wrap|Line Numbers
  1. s = encrypt('temple of doom')
  2. print s
  3. print decrypt(s)
Sep 30 '08 #4
Netwatcher
58 New Member
i need to decrypt binary, which example will work in that case?
is there a shortcut to create a Bin dictionary?
Oct 1 '08 #5
Netwatcher
58 New Member
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
Oct 1 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2423
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 supported. In people's experiences, have hosting companies supporting PHP/MySQL generally provided support for mcrypt? Does anyone recommend another module for encryption/decryption that accompanies the PHP package? Thanks, - Dave
1
2470
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 occurs in the application when you instantiate a new instance of the class as shown below: ---Dim dp As DPAPIComp.DataProtectorComp = New DPAPIComp.DataProtectorComp--- where DPAPIComp is the name of the namespace referenced to in the library
5
7696
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 Service and decrypt the results on the web app. Any example using System.Security.Cryptography namespace (VB not C#, thanks)would be greatly appreciated. Thanks in advance. -Rob
3
2305
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 System; using System.Text; using System.IO;
2
7151
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 French grave... Anyway when I run encryption on a plaintext word like:
2
2432
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 require dependencies on outside applications. I don't know much about encryption. What I would like to do is come up with an encryption/decryption code that will work with my C#/.NET framework windows code (there are a number of cryptographic...
3
3972
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 DataToEncrypt, string Key) { ... } public byte Decrypt(byte DataToDecrypt, string Key)
1
2402
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); This function can encrypt/decrypt only 8bytes block at a time. Thus takes a lot of time during encryption/decryption. Please tell, if there is any other way/function that can take larger block size, or any other function which implements DES in a...
0
2372
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 functions work fine when Two random prime numbers (required to generate public n private key) are within certain range but fails afterwords.All the variables are of datatype ULONGLONG. I m unable to fix up the problem. Is these really a storage problem...
3
3072
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 functions. While my functions read and write files the encryption/decryption is not working properly. My test file has an original length of 66,048 bytes. My encrypted file ends up with 66,056 bytes … 8 bytes more than my original. When I...
0
8987
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9534
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9316
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8239
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4597
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2777
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2211
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.