| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| C++ (Non Visual C++ Issues) Ask or answer C and C++ questions not related to Visual C++. This includes Console programming, Linux programming, or general ANSI C++. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Running Key Cipher
Running Key Cipher:
http://en.wikipedia.org/wiki/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. Unfortunately I have to write this in C so any input would be greatly appreciated, thanks. |
|
#2
|
||||
|
||||
|
Re: Running Key Cipher
Quote:
(83+83)%26+32 == 42 42 is (apart from being the ultimate answer to the question about the life, universe and everything) the ASCII code for * * has not the same ASCII code than H, so I deduce from it that you've not given us the exact algorithm you used. Moreover, there is an irreversible loss of data when you use %26 If you want to encode any ASCII character, you should compute modulo 128 If you want to encode any extended ASCII character, you should compute modulo 256
__________________
"inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards. Club of lovers of the C++ typecasts cute syntax: Only recorded member. Out of memory happens! Handle it properly! Say no to g_new()! |
|
#3
|
|||
|
|||
|
Re: Running Key Cipher
Yeah I just realized I did
((83+83)-122)+32 122 since I have been given that no { } | ~ ad DEL will be used. Either way it doesnt matter about the logic of my little example that I just made up. The main point I was trying to get across is that an "E" can have 2 different values in the encrypted text. |
|
#4
|
||||
|
||||
|
Re: Running Key Cipher
Quote:
In order to decrypt text, you must have the key (that is, you must know the encrypted text as well as the "SPOT RUN SEE" string). Simply, apply the inverse operation: instead of (uncoded_char+key_char)-122+32, you should apply coded_char-32+122-key_char However, your encryption algorithm is weaker than the (weak) running key cipher algorithm. Because you don't use any modulo operation. So, for example, if the encoded contain 'Z' (90), anybody can know that the only possible value for the key & original text is 'Z' (90) for both. If you want to make this algo work, you must choose of a range of values that you accept. For example [32, 96) Then, compute (uncoded_char-32 + key_char-32)%(96-32)+32 in order to cypher the char, or (coded_char-32 - (key_char-32))%(96-32)+32 in order to decypher the char.
__________________
"inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards. Club of lovers of the C++ typecasts cute syntax: Only recorded member. Out of memory happens! Handle it properly! Say no to g_new()! |
|
#5
|
|||
|
|||
|
Re: Running Key Cipher
Ok alright, I understand thanks man, yet the only problem is I do not know the Key I only have the Encrypted text, I have to find out the key first :-S
Thats the trick, and what Im stuck on. |
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|