Computer Science Canada Interesting Cryptography program |
Author: | md [ Tue Oct 18, 2005 10:11 pm ] | ||
Post subject: | Interesting Cryptography program | ||
On the sugestion of wtd, here is an interesting crypto program I wrote; note that this is a cleaned up version that hasn't been tested...
Sorry there is no explanation... I'll post one as soon as I can figure out how to describe it without breaking people's minds... oh and if you can figure out how to decrypt it that'd be cool too ![]() I've updated it so that it actually compiles correctly, thanks wtd It's been updated once more to the version that actually does what it's supposed to... |
Author: | wtd [ Tue Oct 18, 2005 10:20 pm ] | ||
Post subject: | |||
Cleaned up a bit further.
|
Author: | md [ Tue Oct 18, 2005 10:46 pm ] |
Post subject: | |
Ok, so here is how it works... try not to get confused since I'm not so good at explaining ![]() First we start with out string, it can be anything, however only A-Z,a-z will be encoded. We start off with each letter in the alphabet being associated with a key. This key is initially the same letter. As we move through the string we replace the character with the key associated with teh character, and then increment the key. The keys are A-Z,a-z. So if we have a string AAA the first A is replaced with A, the second with B, the thrird with C. Each character has it's own key, so a message that has no repeating character will not change. This can be fixed by using a starting order for the keys that doesn't match, ei. the first A would have a value of say F, B could start as D, etc. An example of the encoding: Input wrote: This is a test of teh encoding algorythm, it may seem like it's doing nothing
at first ut as you progress through the text it just get's more and more random and the encrypted message: Output wrote: This jt a teuu of vfi gncpdkog blhqrywjm, lx ncz vhio mmkj ny'w eropi qszkprj dA gqsxB uC ey Atv ptukukzA Dlvvwlm Enl FmxG rH jxBI mnJ'C pwwo fsf qxxp ygtgyr Here is the actual code encrypted: Encrypted code wrote: // Crypt.cqr : Definfs uhg hovsz sojpw gpt xii dqqtrlj atumkebylsr. // #msfnudk <uzuntg> #ougovel <ptvAvmcm> #qvhpwfn <hwBwodn> xCeDri jjfx kpAy[52]; // 52 lqBz gA Ekrys hzt 26 xvwuA kiBv jwg 26 quwwB lkCx mllCmnFyDD vvsh ExoECxG(pmnF *ty) { qwzEH uAÌI rzBhJn = FKGsAC(vD); ixH(wEL x = 0; y < tBFiMo; z++) { AGN mCD = -1; Bj( (CH[D] >= 'A') && (EI[F] <= 'Z') ) nDE = GJ[H] - 'B'; // kIIGO 26 oEFH FuIG Jl( (KK[L] >= 'o') && (ML[N] <= 'z') ) pHG = OM[P] - 'p' + 26; // NIxP 26 qJHJ Ì Qm(rKI >= 0) { RO[S] = sLJK[tMK]; uNLL[vOM]++; Tn( (wPNM[xQO] > 'a') && (yRPN[zSQ] < 'q')) ATRO[BUS] = 'r'; VvPW Uo( CXTQ[DYU] > 'A') EZVR[FaW] = 'C'; } } } wyVi IPWQKbXS(xzXj) { pAJ(YQR Z = 0; a < 26; b++) GcYT[c] = 'D' + Ìd; qBK(eRS f = 26; g < 52; h++) HdZU[i] = 's' + (j-26); } kST otlT(mUU uLjr, spvM **wNky) { JVnVLeaV(); // Wqf rowg Wxph sOCq Xri tpPWY yQlyrjXZ tszR *qY_urxk = ASmz[1]; // XsZul 0 tY atm yTDnUBs aCtn, 1 ZuEzyk bo bvp vuzqbDur (cF sVWGX vwtwIvdo ÌxuYv ![]() acl::bdZwep HAe_wxAw(yf_xzBx); IBf_yACy += ".zgxJmAn.gyh"; // KzBh iyC BiACj Ejo LDkBEl zCDDc dmp::DAenaEFv EkCFo(Fl_BGEF); fpq::MCgqbGGw NGrDHs(OIt_DHFH.y_huc()); // mPx jJiv dIHr wzJ KnxIeL JoEKy EKGM, NpzQsO Lz, Iqt RLAFMB MC. yANHP(!OÌrGND.QSF()) { ABJf cOGHRg[258]; PsHPE.hSKu(dQIJTi,256); eRKLUj[257] = '\0'; // kSjF GT fV kTkW FtBlbIH(gUMNXm); UVIJWJ << hXOPYn; } QuKYK.CIVlZ(); WZLLaM.DJXma(); obNbpv 0; } **note that hte actual program has some problems with text that isn't a power of 256... but only because it adds giberish to the end... |
Author: | codemage [ Wed Oct 19, 2005 8:45 am ] |
Post subject: | |
That's a bit ENIGMA-esque. |
Author: | beard0 [ Wed Oct 19, 2005 2:15 pm ] |
Post subject: | Re: Interesting Cryptography program |
Cornflake wrote: oh and if you can figure out how to decrypt it that'd be cool too
![]() Impossible: AAAAAAAAAAAAAAAAAAAAAAAAAA Encrypted = ABCDEFGHIJLKMNOPQRSTUVWXYZ ABCDEFGHIJLKMNOPQRSTUVWXYZ Encrypted = ABCDEFGHIJLKMNOPQRSTUVWXYZ So, what is ABCDEFGHIJLKMNOPQRSTUVWXYZ decrypted? ![]() |
Author: | Naveg [ Wed Oct 19, 2005 2:56 pm ] |
Post subject: | |
The decrypting program would have to recognize a set of rules. First, similar to the encrypting program, we give each character an individual counter, starting at its own value, with A being 0. For example, if the encrypted message begins with n consecutive characters, you know that the original message consisted of the first encrypted character n times. Once the characters are no longer consecutive you could check for what the next character is by keeping track of where the counter for each character currently is. Take the first five characters of our alphabet example: AAAAAB becomes ABCDEB Now lets decode ABCDEB: ABCDE are all consecutive, so we know the original message started with 5 A's. The next letter is a B. Since the 'A' counter is now at F (5), we know this cannot be an A. And since no other counters have been initialized (ie. no other characters have been used) we must start a new counter at 'B', Using this new counter,'B' becomes 'B'. What if we added another A to the original message? AAAAABA would become ABCDEBF. Decode ABCDEBF Using the same technique, the first five letters are again all A's, and the sixth is B. What about the F? Well we test the existing counters to see if any are currently in the 'F' position, and sure enough, the 'A' counter is. So the seventh letter in our coded message becomes yet another A. A problem with this logic occurs when multiple counters are in the same position: AAADE would encrypt to ABCDE, but our decoder would decode it as AAAAA. Essentially, this is not a decryptable encryption method. |
Author: | beard0 [ Wed Oct 19, 2005 3:13 pm ] |
Post subject: | |
Naveg: Did you read my post? The one thing that could be done decryption-wise would be to assume that the text is written in a certain lanugage, and use a dictionary to find the most likely fit, though this would be far from foolproof, and would die a painful death when confronted with something such as the c++ code you encoded, and still more painful a death when confronted with the compiled encoded program. |
Author: | Naveg [ Wed Oct 19, 2005 3:18 pm ] |
Post subject: | |
beard0 wrote: Naveg: Did you read my post?
Yes I did, I was just making it clear that the decoding is only flawed when two counters have the same value. More information has to be sent along with the encoded message that enables the decoder to choose the correct character when there are multiple choices. |
Author: | rizzix [ Wed Oct 19, 2005 3:51 pm ] |
Post subject: | Re: Interesting Cryptography program |
beard0 wrote: Cornflake wrote: oh and if you can figure out how to decrypt it that'd be cool too
![]() Impossible: AAAAAAAAAAAAAAAAAAAAAAAAAA Encrypted = ABCDEFGHIJLKMNOPQRSTUVWXYZ ABCDEFGHIJLKMNOPQRSTUVWXYZ Encrypted = ABCDEFGHIJLKMNOPQRSTUVWXYZ So, what is ABCDEFGHIJLKMNOPQRSTUVWXYZ decrypted? ![]() well cornflake.. your algorithm is unfortunately quite.. ehm useless ![]() ![]() nice try though. |
Author: | md [ Wed Oct 19, 2005 5:29 pm ] |
Post subject: | |
Well... given that I thought it up and wrote it to see what it would do... I didn't expect anything to come of it ![]() and by decryptable I mean you can figure out the original message from the decoded text, assuming you try... it won't decrypt strait... [edit] I was going to make it semi workable by adding a number representing the number of times the key used had been changed... but that didn't really make it any easier... methinks I'll just leave it as an example of something completely useless, yet kinda interesting. |