Redshirt2 decryption!

Anything and everything

Moderators: bert_the_turtle, jelco, Chris

User avatar
Jackmn
level5
level5
Posts: 1378
Joined: Thu Feb 07, 2002 5:21 pm

Redshirt2 decryption!

Postby Jackmn » Mon Feb 07, 2005 12:51 am

Not 100% on the algorithm yet. Lemme know if something is wrong.

Used to decrypt your profile files (users/<username>/*.txt).

First, you need to know the encryption key table

It is as follows (0 based):

x1F, x07, x09, x01, x0B, x02, x05, x05
x03, x11, x28, x0C, x23, x16, x1B, x02

Algorithm for DE-cryption is as follows: (Reverse to encrypt, but there are some odd things that have to be done before encryption works.)

Code: Select all

cut out 'redshirt2' header
key index = 0
for each line in crypted file:
   next line if line is blank
   for each character in line
      if( character is < 0x20) write char to output file, next character

      //YES, increment is done BEFORE accessing the table, so the x1F is skipped first time           
      key index = key index + 1
      key index = key index MODULUS 16
      character = character - encryption key at key index
      if character < 0x20 add 0x5f to character
      write decrypted character to output file
   next character
   write newline to output file
next line in file



Perl script:

( Reads from STDIN and prints to STDOUT

Usage: perl decode.pl < encrypted_file > decrypted_file )

decode.pl:

Code: Select all

#!/usr/bin/perl
@table =(
   0x1F, 0x07, 0x09, 0x01, 0x0B, 0x02, 0x05, 0x05,
   0x03, 0x11, 0x28, 0x0C, 0x23, 0x16, 0x1B, 0x02 );

my $first_line = 1;

while(<>)
{
   next if /^$/;
   chomp;

   if( $first_line ) {
      s/^redshirt2//;
      $first_line=0;
   }
   
   my @chars = split(//);
   
   foreach $char (@chars)
   {
      if( ord($char) > 0x20 )
      {
         ++$key_index;
      
         $char = chr(ord($char)-$table[$key_index%16]);
         if( ord($char) < 0x20 )
         { $char = chr( ord($char) + 0x5f ); }
      }
      
   }
   
   print @chars, "\n";
   
}
User avatar
false
level3
level3
Posts: 349
Joined: Fri Mar 29, 2002 5:57 pm
Contact:

Postby false » Mon Feb 07, 2005 8:03 am

Slightly incorrect, but it's nice to see other people figuring it out now. :lol:
~>
Dependent filter
Preserves port number
Does not supports hairpin of media
User avatar
Miah
level5
level5
Posts: 3155
Joined: Mon Oct 13, 2003 7:28 pm
Contact:

Postby Miah » Mon Feb 07, 2005 3:20 pm

Yes, sadly, the NDA tell us not to point out what errors you have, or to do what you just did, Jackmn.

I'm glad someone else is trying, because it was driving me nuts not being able to say anything before.
Darksun
level5
level5
Posts: 6461
Joined: Sat Dec 07, 2002 7:08 pm
Location: 127.0.0.1

Postby Darksun » Mon Feb 07, 2005 6:03 pm

Well no. False can now release his code for the redshirt2 decoder since it's not based on knowledge that can be gained without using any of the phase 2 beta software
User avatar
Jackmn
level5
level5
Posts: 1378
Joined: Thu Feb 07, 2002 5:21 pm

Postby Jackmn » Mon Feb 07, 2005 11:11 pm

false wrote:Slightly incorrect, but it's nice to see other people figuring it out now. :lol:
I think I'm doing fairly well, considering my method involves sitting in front of a debugger and staring at the assembly until everything makes sense =)
Uniter
level0
Posts: 2
Joined: Tue Jul 06, 2004 7:19 pm

Postby Uniter » Thu Mar 03, 2005 7:20 am

Why the hell not, here's some failure C++ code, no error checking, doesnt even bother to remove "redshirt2" you must do it manually HEH

** Thanks Jackmn

Code: Select all

#include <stdlib.h>
#include <stdio.h>
int main() {
        int KTIndex=0;
        char CurrChar, KeyTable[16] = {0x1F, 0x07, 0x09, 0x01, 0x0B, 0x02, 0x05, 0x05, 0x03, 0x11, 0x28, 0x0C, 0x23, 0x16, 0x1B, 0x02};
        FILE * Encd;
        FILE * Outf;
        Encd = fopen ("RedIn.txt","rb");
        Outf = fopen ("RedOut.txt","wb+");
    if ((Encd!=NULL)&&(Outf!=NULL)) {
                while(CurrChar!=EOF) {
                        CurrChar=fgetc (Encd);
                        if(CurrChar > 0x20) {
                                KTIndex++;
                                KTIndex%=16;

                                CurrChar-=KeyTable[KTIndex];

                                if(CurrChar < 0x20)
                                        CurrChar+=0x5f;
                        }
                        fputc (CurrChar , Outf);
                }
        }
        else ;

        return(0);
}
afx
level0
Posts: 2
Joined: Fri Mar 04, 2005 3:56 pm

Postby afx » Fri Mar 04, 2005 4:18 pm

Here's some slightly more functional code for operations both ways.

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void usage(char *);
void enshirt(char *);
void deshirt(char *);

const char table[16] = {0x1f, 0x07, 0x09, 0x01, 0x0b, 0x02, 0x05, 0x05, 0x03,
                        0x11, 0x28, 0x0c, 0x23, 0x16, 0x1b, 0x02};

int
main(int argc, char *argv[])
{
        if (argc < 3)
                usage(argv[0]);

        if (strncmp(argv[1], "-e", 2) == 0)
                enshirt(argv[2]);
        else if (strncmp(argv[1], "-d", 2) == 0)
                deshirt(argv[2]);
        else
                usage(argv[0]);

        exit(0);
}

void usage(char *progname)
{
        printf("Usage: ./%s [-e] [-d] filename\n", progname);
        exit(1);
}

void deshirt(char *filename)
{
        int i;
        char cp, *line;
        FILE *fp;

        if ((fp = fopen(filename, "r")) == NULL) {
                printf("Unable to open: %s\n", filename);
                exit(1);
        }

        fgets(line, 10, fp);

        if (strncmp(line, "redshirt2", 9) == 0) {
                fseek(fp, 9L, SEEK_SET);
        } else {
                printf("Error: Not a redshirt2 file\n");
                exit(1);
        }

        while (cp != EOF) {
                cp = fgetc(fp);
                if (cp > 0x20) {
                        i++;
                        i %= 16;
                        cp -= table[i];

                        if (cp < 0x20)
                                cp += 0x5f;
                }
                printf("%c", cp);
        }

        return;
}

void enshirt(char *filename)
{
        int i;
        char cp;
        FILE *fp;

        if ((fp = fopen(filename, "r")) == NULL) {
                printf("Unable to open: %s\n", filename);
                exit(1);
        }

        printf("redshirt2");

        while (cp != EOF) {
                cp = fgetc(fp);
                if (cp > 0x20) {
                        i++;
                        i %= 16;
                        cp += table[i];

                        if (cp < 0x20)
                                cp -= 0x5f;
                }
                printf("%c", cp);
        }

        return;
}



Thanks for the key table.
Cade
level0
Posts: 5
Joined: Sat Mar 05, 2005 4:34 am
Contact:

Postby Cade » Sat Mar 05, 2005 4:40 am

Vb Code

Code: Select all

Dim Kt(16 - 1) As String
Dim CP As Integer
Dim I As Integer
Dim KtI As Integer
Private Sub Form_Load()
Kt(0) = &H1F
Kt(1) = &H7
Kt(2) = &H9
Kt(3) = &H1
Kt(4) = &HB
Kt(5) = &H2
Kt(6) = &H5
Kt(7) = &H5
Kt(8) = &H3
Kt(9) = &H11
Kt(10) = &H28
Kt(11) = &HC
Kt(12) = &H23
Kt(13) = &H16
Kt(14) = &H1B
Kt(15) = &H2
End Sub
Private Sub Decrypt()
KtI = 0
Text1.Tag = ""
For I = 1 To Len(Text1.Text)
CP = Asc(Mid(Text1.Text, I, 1))
If CP > &H20 Then
KtI = KtI + 1
KtI = KtI Mod 16
CP = CP - Kt(KtI)
If CP < &H20 Then CP = CP + &H5F
End If
DoEvents
Text1.Tag = Text1.Tag & Chr(CP)
Next
Text1.Text = Text1.Tag
Text1.Tag = ""
End Sub

Ported from the C code above, because when compiled and decrypting, it crashed.

Decryption works perfectly, but I cant get encryption to work. The difference between encryption and decrpytion is,

Code: Select all

CP = CP + Kt(KtI)
If CP < &H20 Then CP = CP - &H5F

But the second line, if I put a breakpoint (inside the if statement) and decrypt something, it never gets called, meaning the line If CP < &H20 in encryption is useless. Any help with encryption?
afx
level0
Posts: 2
Joined: Fri Mar 04, 2005 3:56 pm

Postby afx » Sat Mar 05, 2005 8:12 pm

Cade wrote:...
Ported from the C code above, because when compiled and decrypting, it crashed.

Decryption works perfectly, but I cant get encryption to work. The difference between encryption and decrpytion is,

...

But the second line, if I put a breakpoint (inside the if statement) and decrypt something, it never gets called, meaning the line If CP < &H20 in encryption is useless. Any help with encryption?


Yeah sorry, only tested the code on freebsd. Works fine for me for forwards and backwards if I need to edit any files.

Sorry, I don't know VB at all.
User avatar
NeoThermic
Introversion Staff
Introversion Staff
Posts: 6254
Joined: Sat Mar 02, 2002 10:55 am
Location: ::1
Contact:

Postby NeoThermic » Sat Mar 05, 2005 8:25 pm

Cade wrote:Vb Code

Code: Select all

Dim Kt(16 - 1) As String
Dim CP As Integer
Dim I As Integer
Dim KtI As Integer
Private Sub Form_Load()
Kt(0) = &H1F
Kt(1) = &H7
Kt(2) = &H9
Kt(3) = &H1
Kt(4) = &HB
Kt(5) = &H2
Kt(6) = &H5
Kt(7) = &H5
Kt(8) = &H3
Kt(9) = &H11
Kt(10) = &H28
Kt(11) = &HC
Kt(12) = &H23
Kt(13) = &H16
Kt(14) = &H1B
Kt(15) = &H2
End Sub
Private Sub Decrypt()
KtI = 0
Text1.Tag = ""
For I = 1 To Len(Text1.Text)
CP = Asc(Mid(Text1.Text, I, 1))
If CP > &H20 Then
KtI = KtI + 1
KtI = KtI Mod 16
CP = CP - Kt(KtI)
If CP < &H20 Then CP = CP + &H5F
End If
DoEvents
Text1.Tag = Text1.Tag & Chr(CP)
Next
Text1.Text = Text1.Tag
Text1.Tag = ""
End Sub



:shock: It brings back memories of the Uplink sourcecode :shock:

Edit: Code above doesn't seem to do anything. Its also missing an End If for one of the loops

NeoThermic
Last edited by NeoThermic on Sat Mar 05, 2005 8:50 pm, edited 1 time in total.
Darksun
level5
level5
Posts: 6461
Joined: Sat Dec 07, 2002 7:08 pm
Location: 127.0.0.1

Postby Darksun » Sat Mar 05, 2005 8:27 pm

afx, I get a segfault when I try and run your code on Cygwin, compiled with GCC
User avatar
Jackmn
level5
level5
Posts: 1378
Joined: Thu Feb 07, 2002 5:21 pm

Postby Jackmn » Sat Mar 05, 2005 10:36 pm

afx wrote:Yeah sorry, only tested the code on freebsd. Works fine for me for forwards and backwards if I need to edit any files.

Sorry, I don't know VB at all.
Works fine for me on windows.

Try running debugging it with GDB Dark.
Cade
level0
Posts: 5
Joined: Sat Mar 05, 2005 4:34 am
Contact:

Postby Cade » Sun Mar 06, 2005 1:43 am

Whole VB Code, works properly when decoding but not encoding. Anyone know why? Command1 decodes, command2 encodes, assuming the data is stored in text1.text

Code: Select all

Dim Kt(16 - 1) As String
Dim CP As Integer
Dim I As Integer
Dim KtI As Integer
Private Sub Command1_Click()
KtI = 0
Text1.Tag = ""
For I = 1 To Len(Text1.Text)
CP = Asc(Mid(Text1.Text, I, 1))
If CP > &H20 Then
KtI = KtI + 1
KtI = KtI Mod 16
CP = CP - Kt(KtI)
If CP < &H20 Then CP = CP + &H5F
End If
DoEvents
Text1.Tag = Text1.Tag & Chr(CP)
Next
Text1.Text = Text1.Tag
Text1.Tag = ""
End Sub
Private Sub Command2_Click()
KtI = 0
Text1.Tag = ""
For I = 1 To Len(Text1.Text)
CP = Asc(Mid(Text1.Text, I, 1))
If CP > &H20 Then
KtI = KtI + 1
KtI = KtI Mod 16
CP = CP + Kt(KtI)
If CP < &H20 Then
CP = CP - &H5F
End If
End If
DoEvents
Text1.Tag = Text1.Tag & Chr(CP)
Next
Text1.Text = Text1.Tag
Text1.Tag = ""
End Sub
Private Sub Form_Load()
Kt(0) = &H1F
Kt(1) = &H7
Kt(2) = &H9
Kt(3) = &H1
Kt(4) = &HB
Kt(5) = &H2
Kt(6) = &H5
Kt(7) = &H5
Kt(8) = &H3
Kt(9) = &H11
Kt(10) = &H28
Kt(11) = &HC
Kt(12) = &H23
Kt(13) = &H16
Kt(14) = &H1B
Kt(15) = &H2
End Sub

User avatar
NeoThermic
Introversion Staff
Introversion Staff
Posts: 6254
Joined: Sat Mar 02, 2002 10:55 am
Location: ::1
Contact:

Postby NeoThermic » Sun Mar 06, 2005 2:57 am

Cade wrote:

Code: Select all

Dim I As Integer


You might want to use Long if you feel the need to go after the language file, else you'll get an overflow.

NeoThermic
User avatar
Jackmn
level5
level5
Posts: 1378
Joined: Thu Feb 07, 2002 5:21 pm

Postby Jackmn » Sun Mar 06, 2005 3:32 am

Cade wrote:Whole VB Code, works properly when decoding but not encoding. Anyone know why? Command1 decodes, command2 encodes, assuming the data is stored in text1.text
Not to be a prick, but you really need to tab your code.

Return to “General”

Who is online

Users browsing this forum: No registered users and 1 guest