473,405 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Where to start for a cryptogram?

Thekid
145 100+
Can I get some pointers on writing a program to decipher cryptograms? I'm not sure where to start. This is an example:

bthhy gwtqt! wyo pl cyxq zkv eypre?
Mar 7 '07 #1
7 4775
ilikepython
844 Expert 512MB
Can I get some pointers on writing a program to decipher cryptograms? I'm not sure where to start. This is an example:

bthhy gwtqt! wyo pl cyxq zkv eypre?
I think you should start off with a huge word list in a file so python can know what to look for but i'm not sure. Just an idea.
Mar 7 '07 #2
ilikepython
844 Expert 512MB
Wait do you mean like a word scrambler/unscrambler or a kind of like a decoder that tries to decode the message??
Mar 7 '07 #3
Thekid
145 100+
A decoder. I have written a word unscrambler but I like to do cryptograms from a crossword puzzle book and thought it would be fun to try to write a program that could decipher them.
Mar 7 '07 #4
bartonc
6,596 Expert 4TB
A decoder. I have written a word unscrambler but I like to do cryptograms from a crossword puzzle book and thought it would be fun to try to write a program that could decipher them.
After unscrambling a word you could do something like:
Expand|Select|Wrap|Line Numbers
  1. import win32com.client
  2.  
  3. msword = win32com.client.Dispatch("Word.Application")
  4.  
  5. string = "Here is some texxt with a coupple of problems"
  6.  
  7. for word in string.split():
  8.     if msword.CheckSpelling(word):
  9.        print "!%s! OK!" % word
  10.     else:
  11.        print "?%s? ->"%word,
  12.        suggestions = msword.GetSpellingSuggestions(word)
  13.        for suggest in suggestions:
  14.            print suggest.Name,
  15.        print
  16.  
on Windows or check with ispell using popen() on *nix.
Mar 7 '07 #5
Thekid
145 100+
Ya, I don't need to unscramble the words first but I have written a simple word unscrambler before. I was wondering where to start to write a program to solve a cryptogram without a key. So if:
a = "h"
b = "i"
c = "j"
d = "x"
e = "t"
f = "r"
g = "e"

and the puzzle was: ab eagrg!
the solution would be: hi there!

BUT.....how can it be done without having a key to the solution? Cryptograms are fun and I can usually solve them with paper and pencil but I figured I'd give myself a challenge and see if I could come up with a program that could do it.
Mar 7 '07 #6
bartonc
6,596 Expert 4TB
Ya, I don't need to unscramble the words first but I have written a simple word unscrambler before. I was wondering where to start to write a program to solve a cryptogram without a key. So if:
a = "h"
b = "i"
c = "j"
d = "x"
e = "t"
f = "r"
g = "e"

and the puzzle was: ab eagrg!
the solution would be: hi there!

BUT.....how can it be done without having a key to the solution? Cryptograms are fun and I can usually solve them with paper and pencil but I figured I'd give myself a challenge and see if I could come up with a program that could do it.
That's a good one. For a given problem that you know how to solve with paper and pencil, start by writing down the steps you take with the given info, what new info you have after step 1, and so on, until the entire algorithm unfolds. Once you have a possible algorithm, then it's time to ask "how can I make the computer perform this algorithm?".
Mar 7 '07 #7
Thekid
145 100+
I found the following at:
http://mail.python.org/pipermail/python-list/2002-September/165558.html

Expand|Select|Wrap|Line Numbers
  1. """
  2.  Ha'f ahoy ad ayfa wdqr srxhekdpyr! H phmm zhby
  3.  fhv odeajf dc cryy pys jdfahez ad ajy chrfa kyrfde
  4.  ad fdmby ajhf irwkadzrxo. Ixe wdq chzqry ha dqa?
  5.  
  6.  Fheiy wdq jxby axgye ow ijxmmyezy xet tyirwkayt
  7.  ajy fyirya oyffxzy, H phmm ybye zhby wdq ajy
  8.  irwkadzrxo-oxghez fdqriy idty ad xoxuy wdqr
  9.  crhyetf!
  10.  """
  11.  hokdra fwf, farhez, rxetdo
  12.  ihkjyr = mhfa(farhez.myaayrf[:26])
  13.  rxetdo.fjqccmy(ihkjyr)
  14.  ihkjyr = "".ldhe(ihkjyr)
  15.  ihkjyr += ihkjyr.qkkyr()
  16.  oxk = {}
  17.  cdr kmxhe, irwka he uhk(farhez.myaayrf, ihkjyr):
  18.      oxk[kmxhe] = irwka
  19.  cdr mhey he dkye(fwf.xrzb[1]):
  20.      krhea "".ldhe([oxk.zya(ij,ij) cdr ij he mhey])[:-1]
  21.  
  22.  
Now if I was to start thinking this one out, I'd start with single letters which are usually either 'A' or 'I' and also take a look at any words with an appostrophe, then I'd look for possible 'and' or 'the' type structures, double letters,and any questions, which usually start with: is, am, are, who, what, where, when, how, why, can, can't, do, don't, may, will, won't, etc. but again the appostrophe comes in to play as well as the amount of letters in the word.
I have the solution to this one but wouldn't find it hard to start myself. Here's someones solution to it:
Expand|Select|Wrap|Line Numbers
  1. def decrypt(yourstring):
  2.     dedict = {'F': 'S', 'I': 'C', 'H': 'I', 'a': 't', 'c': 'f', 'b': 'v', 'e': 'n',
  3.     'd': 'o', 'f': 's', 'i': 'c', 'h': 'i', 'k': 'p', 'j': 'h', 'm': 'l',
  4.     'l': 'j', 'o': 'm', 'q': 'u', 'p': 'w', 's': 'b', 'u': 'z', 't': 'd',
  5.     'w': 'y', 'v': 'x', 'y': 'e', 'x': 'a', 'z': 'g', 'g': 'k'}
  6.     return "".join([dedict.get(i,i) for i in yourstring])
  7.  
  8. returns 
  9.  
  10.     """
  11.     It's time to test your brainpower! I will give
  12.     six months of free web hosting to the first person
  13.     to solve this cryptogram. Can you figure it out?
  14.  
  15.     Since you have taken my challenge and decrypted
  16.     the secret message, I will even give you the
  17.     cryptogram-making source code to amaze your
  18.     friends!
  19.     """
  20.     import sys, string, random
  21.     cipher = list(string.letters[:26])
  22.     random.shuffle(cipher)
  23.     cipher = "".join(cipher)
  24.     cipher += cipher.upper()
  25.     map = {}
  26.     for plain, crypt in zip(string.letters, cipher):
  27.         map[plain] = crypt
  28.     for line in open(sys.argv[1]):
  29.         print "".join([map.get(ch,ch) for ch in line])[:-1]
  30.  
This was posted in 2002 but I didn't know if some of this code could be used without the given key.
Mar 7 '07 #8

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

Similar topics

2
by: Nat | last post by:
Hi there, I have code as following but it returns error Error Type: Microsoft VBScript compilation (0x800A03F6) Expected 'End' /urbisjhdintranet/metadata/resultList.asp, line 324 which is the...
2
by: GAVO. | last post by:
This probably is not the best group to post this question but any ways. I've been working with ms access for the last couple of years and gotten very good at it. I have never been on any ms...
7
by: Mr. Mountain | last post by:
In the following code I simulate work being done on different threads by sleeping a couple methods for about 40 ms. However, some of these methods that should finish in about 40 -80 ms take as long...
25
by: John Salerno | last post by:
Just a quickie for today: Is it common (and also preferred, which are two different things!) to create a function that has the sole job of calling another function? Example: for fun and...
14
by: Odinn | last post by:
Greetings , This is my first year at programming and 3rd week at this so count me as a pure newbie. I am trying to make a program that gets a number and prints out starts as this: For input 3 :...
3
by: saundra | last post by:
This appears to be the code that is giving me trouble. Can someone help <? include("common.php"); require_once("$HeaderFile"); if(empty($_GET)){ $Start = '0'; }else{ $Start = $_GET;
5
by: =?Utf-8?B?cm9jY28=?= | last post by:
Hello, easy question: - what are the best books to start learning C#? Thanks! Rocco
2
by: Ceebaby via AccessMonster.com | last post by:
Hi Folks I wondered if someone could point me in the right direction before I completely tear my hair out. I have a user selection form where options can be selected for a report. Users now...
37
by: Phlip | last post by:
1230987za wrote: Kanze is a classically-trained "unit tester". In some circles "unit" is a QA concept - specifically, if a test fails, you only need to inspect one unit. So "units" are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.