Solved

Dictionary help needed

Posted on 2007-03-19
4
386 Views
Last Modified: 2010-04-16
I'm trying to implement a forward search attack (i.e. a brute force generating and testing all possible combinations) on 2 words encrypted in RSA whose contents may include A-Z and [space] (which might be used for padding), that is 65-90 and 32 ASCII. I have some (very limited) knowledge of Python but can't get the dictionary contents right. I've included the code below, can someone please give me some pointers.

scrambled1 = "3648141"
scrambled2 = "5608387"
dictionary1 = {}
code=0
e=5
n=21508387

for a in range(65,91):
    for b in range(65,91):
        for c in range(65,91):
            plain=(a<<16)+(b<<8)+c
            code = pow(plain,e,n)
          dictionary1[code]=plain

for d in range(65,91):
      for e in range(65,91):
            plain=(f<<16)+(g<<8)+32
              code = pow(plain,e,n)
            
            dictionary1[code]=plain

dictionary1[code]=scrambled2
dictionary1[code]=scrambled2
0
Comment
Question by:mark_667
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 17

Expert Comment

by:ramrom
ID: 18751296
I don't know enough about RSA encryption to even begin to guess what you mean by "can't get the dictionary contents right". Perhaps if you explain what the contents should be and what you are getting we could help.
0
 
LVL 15

Accepted Solution

by:
mish33 earned 125 total points
ID: 18754552
I don't understand why you need dictionary at all:

scrambled1 = "3648141"
scrambled2 = "5608387"
e=5
n=21508387
AZ = range(65,91)
AZspace = list(AZ)+[32]

for a in AZ:
    for b in AZ:
        for c in AZspace:
            plain=(a<<16)+(b<<8)+c
            code = pow(plain,e,n)
            if code==scrambled1:
               print 'found 1', ''.join(chr(x) for x in (a, b, c))
            if code==scrambled2:
               print 'found 2', ''.join(chr(x) for x in (a, b, c))
0
 
LVL 1

Author Comment

by:mark_667
ID: 18754969
The dictionary holds all plaintext possibilities for the specified range in one column and stores the encrypted versions of these in the other giving a lookup table.

This should allow me to match the scrambled words to one of the encrypted entries and look at the corresponding plaintext entry to get a result. As you can see if you run it, this does not work. I tried the code mish33 posted above but when I printed the contents of code to a file to check  what was being produced the first scrambled word was present but not the second.

This could only happen if I had not covered all possibilities when generating values for code. Also, I had no way of looking up the corresponding plaintext when a match was found. Here's a modified version I've tried:

scrambled1 = "3648141"
scrambled2 = "5608387"
e=5
n=21508387
AZ = range(65,91)
AZspace = list(AZ)+[32]
outfd=open('outfile.txt','wb')

for a in AZspace:
    for b in AZspace:
        for c in AZspace:
            plain=(a<<16)+(b<<8)+c
            code = pow(plain,e,n)

          outfd.write('%s \n' % str(plain))
          outfd.write('%s \n' % str(code))
              outfd.write('%s \n')

            if code==scrambled1:
               print 'found 1', ''.join(chr(x) for x in (a, b, c))
            if code==scrambled2:
               print 'found 2', ''.join(chr(x) for x in (a, b, c))

outfd.close()

I think the problem is the space. Instead of encrypting it with the characters in the range A-Z it seems to just be adding it on to the end of what is encrypted, thus not generating all of the necessary possibilities. Any further thoughts?
0
 
LVL 15

Expert Comment

by:mish33
ID: 18756944
Check that scrambled2 really is 5608387, because that number is encoded by combination
a,b,c = 209, 106, 126 (string 'Ñj~') which far outside AZspace.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A set of related code is known to be a Module, it helps us to organize our code logically which is much easier for us to understand and use it. Module is an object with arbitrarily named attributes which can be used in binding and referencing. …
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question