# How can I break REDSHIRT / REDSHIRT2 encryption?

Recently, a user on Gaming.SE asked a question about whether the user password in the video game Uplink could be modified after being initially set. The game does not contain an option to change the password, and the password is repeatedly displayed in plain text throughout in the game. Obviously, this is a problem if a user accidentally uses a valuable password.

The game stores the password in the save file, which could be edited, except that the save file is encrypted using Introversion's REDSHIRT encryption scheme. How do the REDSHIRT and REDSHIRT2 encryption schemes work, and what is the decryption algorithm?

Be Aware: Details of REDSHIRT encryption have already been discovered and published:

I'm asking this question only to benefit future users. I do plan to post my own answer, but I'll be happy to upvote and accept anyone who explains it better than I can.

-

## migrated from stackoverflow.comJan 2 '12 at 12:36

This question came from our site for professional and enthusiast programmers.

if you are a programmer and you already have source code to the decryption tool given by mario konrad then you don't need an answer to this question :) –  Ahmed Masud Jan 1 '12 at 7:05
@AhmedMasud - I'm asking here because Mario may decide to someday take down his source. –  Steve V. Jan 1 '12 at 7:07
Steve, it's good to think of future users, but this is not really a programming question. –  owlstead Jan 1 '12 at 22:39
This is kind of like worrying that the recipe for ice will be lost. –  David Schwartz Jan 2 '12 at 12:59
"Is it practical" -> Yes, it is asking how to break a particular kind of encryption. "Is it answerable" -> Yes, there is one correct answer. "Is it based on an actual problem you face?" -> Yes "Is it okay to ask a question even when you know the answer?" -> Yes I asked the question in good faith - no spam intended. If you still disagree, please tell me. –  Steve V. Jan 7 '12 at 21:19

I'm not going to explain this but after looking at redshirt.c; the core part of the program is that after skipping the header (which is "REDSHIRT" (9 bytes includes an ending null byte)), it has a loop which does:

int j;
j = (j & 0x7F) + (~j & 0x80);


Which, if you don't recognize it, maps 128-255 to 0-127 and 0-127 to 128-255. (I think this might be the same as swapping the nibbles of a byte.) and is the same as j = (j + 128) % 256.

-
I don't think it's swapping the nibbles, I think it's flipping the first bit. (It's also XOR'ing by 128) –  Steve V. Jan 1 '12 at 7:53
Yep, it's the same as j ^= 128; –  David Schwartz Jan 2 '12 at 12:58

REDSHIRT is a simple XOR encryption scheme, where each byte of the file (except the 9-byte header) is XOR'ed by 128.

The following Python code will decrypt it:

b = bytearray(open('a.in', 'rb').read())