Programming Challenge!!!

I have recently learned something and now I am posting it here as a challenge to anyone. The rules are simple: All answers must please be ROT13 encrypted.
The challenge: You have two ints x and y you have put the contents of x into y and vice verse, you may not use: pointers, another variable. Your code may only be on one line (';' terminates a line).

Please let me know of any errors and please ENCRYPT YOUR ANSWERS.
Last edited on
Your ROT13 code isn't correct; it isn't supposed to be applied to numbers or punctuation. Also, the idea of ROT13 is that you use the same program to encrypt and decrypt. To do that, you need to check whether each character is greater than 13th in the alphabet or not.

Here's an example cypher: http://cplusplus.com/articles/4iLN8vqX/
Thank you chrisname, i will fix it use chrisname's source
Last edited on
The problem with ROT13 in this case is that it doesn't encrypt syntax(special characters), in my case its just changed x to k and y to l.
Last edited on
That's what it's supposed to do. You could change the code in the article above if you wanted to, or you could use a xor cypher which would be more suitable.
Instead of ROT13 why not specify an online encryption tool and an encryption method and we can PM you the key used. But then again we could just PM our answers.
Let's see if this works. Sorry for this not being ROT13, but it's more fun this way.

http://www.cplusplus.com/forum/lounge/60149/

Edit: epic fail. Pastebin messes them up.
Edit 2: too lazy to code a binary-to-text converter so...
http://d01.megashares.com/dl/VLLYVoJ/challenge01.cpp.part1
http://d01.megashares.com/dl/ube6rxk/challenge01.cpp.part2
Last edited on
1
2
3
4
5
//Assumes either (INT_MAX+1 == INT_MIN and INT_MIN-1 == INT_MAX)
//            or (INT_MAX == +∞ and INT_MIN == -∞)
x=x+y,
y=x-y,
x=x-y;

Proof:
1
2
3
4
5
6
//x=x+y
x1 = x+y
//y=x-y
y1 = x1-y = x+y-y = x
//x=x-y
x2 = x1-y1 = x+y-x = y
Last edited on
Canonical answer:

1
2
// swap x and y
x ^= y,   y ^= x,   x ^= y;
^That doesn't work if x == y && x != 0

Edit:
 
std::swap(x, y);


:P
Last edited on
Yes, it assumes x and y are distinct. Throw a branch in there if it is an issue. :O)
1
2
3
4
5
6
7
__asm
{
    mov eax, x
    mov ebx, y
    mov x, ebx
    mov y, eax
};

:B
It doesn't work?
1
2
3
4
5
6
//x^=y
x1 = x^y = x^x = 0
//y^=x
y1 = x1^y = 0^y = y
//x^=y
x2 = x1^y1 = 0^y = y
Maybe something with signs I'm not seeing?
Last edited on
Topic archived. No new replies allowed.