Challenge: Crack the code

-8

1

I have created a simple encryption algorithm. Your challenge, if you choose to accept it, is to re-produce the algorithm that encodes one string into it's encoded counterpart and then back again by decoding.

The winning criteria is as follows:

  • Provide the algorithms that was used to produce the answers
  • Produce the algorithms in 200 bytes or less per algorithm
  • The algorithms have to be effective on all strings

The smallest algorithms or code snippets that produces the correct answers wins.

Strings:

Start:                   | Out:
-------------------------|-----------------------
I'll undefine your face  | M-tv,â~hknszs0}u}|,tqgk
This is a test           | Xnq},wâ$g(~qüä
Another example          | Etw~tsé$kÇky~|i
Meaning of life: 42      | Qkixu|w$un*xwvi@(>>

Happy cracking!

TechnoCF

Posted 2014-09-10T21:24:36.010

Reputation: 15

Question was closed 2014-09-19T11:42:58.333

3Please do not delete and repost questions. The correct way to modify a question is via an edit. – Doorknob – 2014-09-10T21:25:25.753

3Encryption: print'M-tv,â~hknszs0}u}|,tqgk'. Decryption: print'I'll undefine your face'. Do I win? (This problem is really underspecified.) – xnor – 2014-09-10T21:41:05.673

1You should (at a minimum) add several (at least) plaintext-encrypted pairs and add the condition that it must output them all correctly. – Geobits – 2014-09-10T21:42:25.623

@xnor: You don't. Encryption is bijective. – Dennis – 2014-09-10T21:44:45.597

1@Dennis In that case, I'll just xor the byte diff. Techno, I think what you intend is for us to figure out what cool algorithm you used to do the encryption, but with one example, people will almost surely do something cheap that just works for those strings. – xnor – 2014-09-10T21:47:10.977

This question appears to be off-topic because its winning criterion and its tags contradict themselves. – Timtech – 2014-09-18T21:47:42.747

Answers

7

CJam, 21 18 bytes each

Try it online. Note that the online interpreter doesn't use the same encoding as the OP, so the characters in the upper 128 bytes won't match.

Encryption

l_,{(I7%2+2*+o}fI;

Decryption

l_,{(I7%2+2*-o}fI;

How it works

Encryption consists in adding 4, 6, 8, 10, 12, 14 and 16 to the first 7 bytes, printing those bytes and starting over. Decryption simply subtracts instead of adding.

l_,                 " Read one line S from STDIN and push its length L. ";
   {          }fI   " For each I from 0 to L - 1: ";
    (               " Shift a character C from the string. ";
     I7%2+2*        " Calculate J := I % 7 + 2 * 2. ";
            +       " Add J to the char code of C. ";
             o      " Print the encrypted character. ";
                 ;  " Discard S. ";

Dennis

Posted 2014-09-10T21:24:36.010

Reputation: 196 637

4Wow, this is actually shorter than hardcoding the strings themselves. – Doorknob – 2014-09-10T21:55:21.043

Would another string encoded using method with with this code? For example: "This is a test" -> "Xnq},wâ$g(~qüä" – TechnoCF – 2014-09-10T22:05:39.770

I'll leave this open for other people to submit but this answer works. I'll put down the fact that it doesn't work perfectly on all strings because of the online interpreter. – TechnoCF – 2014-09-10T22:12:03.903

Also @Doorknob, hard-coding the strings would not be a valid answer. – TechnoCF – 2014-09-10T22:13:00.513

1@TechnoCF: Actually, hard-coding the strings is a valid answer, because the problem is designed to address a sample-space which consists of only the 4 datapoints that you're giving. Since an encryption solution entails a bijection between the original space and target space, a hard-coded answer automatically satisfies the bijection criterion. – DumpsterDoofus – 2014-09-11T14:40:23.133

@DumpsterDoofus: It is not a valid answer as me, the creator of the challenge, says it is not a valid answer. – TechnoCF – 2014-09-11T18:28:39.230

1

JavaScript 166

function e(s,v,n) {
n=0,v=!v?2:v
return s.replace(/./g,function(m){
m=String.fromCharCode(m.charCodeAt(0)+(n%14+v*2))
n+=v
return m})}
function d(s){
return e(s,-2)
}

wolfhammer

Posted 2014-09-10T21:24:36.010

Reputation: 1 219