LinuxQuestions.org
Have you listened to LQ Radio?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Thread Tools Search this Thread
Old 11-15-2006, 11:15 PM   #1
Herrkutt
LQ Newbie
 
Registered: Apr 2006
Location: CANADA
Distribution: Ubuntu Edgy
Posts: 5
Thanked: 0
Running Key Cipher


[Log in to get rid of this advertisement]
Running Key Cipher:

Text: "SEE SPOT RUN"
Key: "SPOT RUN SEE"
Crypt: "H76tsDFD@G<5"

What I did here was add the ASCII values of the top and bottom mod 26 and add 32, then convert back to letters.

Anyone have any ideas on how this could be decrypted given a much larger encrypted piece of text (38,000 Characters)?
I was thinking using some sort of patter or frequence analysis but im stuck.
Thanks in advance
_________________
-------------------
~HerrKutt
Herrkutt is offline     Reply With Quote
Old 11-16-2006, 04:55 PM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu (x86), Debian (PPC)
Posts: 3,495
Thanked: 6
The operation you described doesn't match your results. e.g. the first character:

Text = S, Key = S.
ASCII S = 83
((83 + 83) mod 26) + 32 == 42 == '*'

Or did you mean
83 + (83 mod 26) + 32 == 120 == 'x'

Can you show your working?
matthewg42 is offline     Reply With Quote
Old 11-17-2006, 03:17 PM   #3
Herrkutt
LQ Newbie
 
Registered: Apr 2006
Location: CANADA
Distribution: Ubuntu Edgy
Posts: 5
Thanked: 0

Original Poster
Yeah I noticed I did the wrong calculation.

But thats not really what I was trying to ask.
My main point that I wanted to show is that the two E's in the plain text can be 2 different letters in the encrypted text.

So Im stuck at trying to decipher the crytp text to find the key AND the plain text, since im only give the encrypted as input (38,000 characters from ASCII 32-126).

I hope that clears up my question a bit more.
Thanks
Herrkutt is offline     Reply With Quote
Old 11-17-2006, 04:16 PM   #4
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu (x86), Debian (PPC)
Posts: 3,495
Thanked: 6
Yes, using mods can erase information. There's no accurate way to reverse a mod operation like this. Consider the letters A..Z having values 0..25, and using mod 3 (never mind the addition of the key value for now).
Code:
Cleartext, value     value mod 3     Ciphertext
A, 0                 0               A
B, 1                 1               B
C, 2                 2               C
D, 3                 0               A
E, 4                 1               B
F, 5                 2               C
G, 6                 0               A
...
Given a cipher text character A, you can't tell which letter was the cleartext, it could have been A, D, G, ...
Now if there's only a few cases where you have an ambiguous reverse, and you know more or less what to expect, you can do some statistical analysis and make an educated guess as to the result.

For example, imagine some scheme which when decrypted, results in "HEL?O WORLD", the ? being possibly an L or a B... you can guess that it should be an L... but you are assuming the cleartext was English and didn't have spelling mistakes in it.

Whether or not information loss occurs depends on the exact algorithm, hence my request for clarification of yours. I suspect it does.
matthewg42 is offline     Reply With Quote
Old 11-17-2006, 09:13 PM   #5
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD amd64 8.0-RELEASE, Slackware64 13.0, Slackware 12.1, Ubuntu Server 8.04, Kubuntu 9.04
Posts: 2,222
Thanked: 45
Quote:
Originally Posted by matthewg42
The operation you described doesn't match your results.
OP didn't say anything about ASCII. Besides, most widespread encryption algorithms aren't expressed in an ASCII way.

In order for it to work, however, OP will have to project between ASCII and letters (if using a compiled language, that is.) The easiest way to do this is subtract the character 'A' or 'a' from each letter. The problem with OP's method is the space character, and possibly commas or periods. This makes the finite field greater than 26 values. So (Herrkutt); you need to decide what the set of characters you want are.

Once you project from ASCII to your 26 or so character field, just perform all operations modulo the size (e.g. 26), then reverse the projection back to ASCII. Example:
Code:
char data[128];
char code[128];

//...

for (int i = 0; i < 128; i++)
{
  data[i] -= 'A';

  data[i] += code[i] + 32;
  data[i] %= 26;

  data[i] += 'A';
}
ta0kira
ta0kira is offline     Reply With Quote
Old 11-20-2006, 11:07 PM   #6
Herrkutt
LQ Newbie
 
Registered: Apr 2006
Location: CANADA
Distribution: Ubuntu Edgy
Posts: 5
Thanked: 0

Original Poster
Thanks guys so far for your help.
Anyway Ive been given some more information on the key.
Its actually a Vigenere Cipher but the key is really long.
The text file is about 38000 characters long and the key file is at least 50%.
So what I was thinking is finding out first the length of the key and then possibly doing a comparison from where the key starts again and the beginning of the message.

Now the algorithm im using doesnt actually use mod (that was my mistake)

Text: "SEE SPOT RUN"
Key: "SPOT RUN SEE"
Crypt: "H76tsDFD@G<5"

What I did was take the ASCII of S in the Text (call that T(S)) and then Ascii of the S in Key (K(S)) and added the two together subtracted 126 and added 32 (min value)

so T(S) + K(S) = 83+83= 166
-126 = 40
+32 = 72 = H

Ive defined the character set to go from ASCII 32-122 for the key and plaintext but from 32-126 for the encrypted key.
Once again any help would be awesome.

Last edited by Herrkutt; 11-20-2006 at 11:10 PM..
Herrkutt is offline     Reply With Quote
Old 11-21-2006, 06:33 AM   #7
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu (x86), Debian (PPC)
Posts: 3,495
Thanked: 6
When you say the key file is at least 50%, do you mean it's at least half as long as the cleartext? One wonders why the person who enciphered the message didn't just go the whole hog and use a one time patch

Do you know the exact key length?

The standard method of attacking a Vigenere cipher is to determine the key length by looking for the distance between bigrams & trigrams (candidate key lengths being factors of common seps), and then splitting the ciphertext up bu taking a character every [keylength], and doing regular freq analysis on that set, and then the next set etc. However, if the key length is half as long as the cleartext, this will be a limited use... I wouldn't know how to go about it in that case.
matthewg42 is offline     Reply With Quote

Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Smart Key Signature ERRORS! How do I delete this bad key from my computer? Balarabay1 Linux - Software 4 09-27-2006 12:01 PM
LXer: 128-bit Block Cipher "Camellia" Announced as Open Source LXer Syndicated Linux News 0 04-19-2006 04:03 AM
Affine Cipher Gato Azul Programming 1 10-15-2005 10:12 AM
True stream cipher in crypto API module? ta0kira Linux - Security 0 07-23-2005 03:10 AM
RSA public key encryption/private key decription koningshoed Linux - Security 1 08-08-2002 08:25 AM


All times are GMT -5. The time now is 04:31 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Advertisement
Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Click Here to receive a complimentary subscription courtesy of LQ.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration