Some code to encrypt/decrypt
After reading this topic in the Introversion forums, I whipped up some Ruby code to do the Redshirt2 encryption/decryption. For those who don't know, Redshirt2 is the fairly simple algorithm used to obscure the user profile files - if you decrypt your user profile files with this, you can modify them and then re-ecrypt them to do pretty much whatever you want, such as enabling later levels and whatnot.
Hrm, perhaps I should play the game again but this time giving myself max research levels...
Anyway, the code is as follows:
#!/usr/bin/env ruby
module Redshirt
TABLE = ( 0x1f, 0x07, 0x09, 0x01, 0x0b, 0x02, 0x05, 0x05,
0x03, 0x11, 0x28, 0x0c, 0x23, 0x16, 0x1b, 0x02 )
def self.deshirt(input, output)
i = 0
input.each_byte do |byte|
if byte > 0x20
i += 1
i %= 16
byte -= TABLE(i)
if byte < 0x20
byte += 0x5f
end
end
output.putc byte
end
end
def self.deshirtfile(filename)
if filename != nil and filename.length > 0 and filename != "-"
begin
File.open(filename, 'r') do |file|
if file.read("redshirt2".length) != "redshirt2"
STDERR.puts "Error: not a redshirt2 file"
exit 1
else
deshirt(file, STDOUT)
end
end
rescue Errno::ENOENT
STDERR.puts "Error: Unable to open file `#{filename}'"
exit 1
end
else
if STDIN.read("redshirt2".length) != "redshirt2"
STDIN.seek(0 - "redshirt2".length, IO::SEEK_CUR)
end
deshirt(STDIN, STDOUT)
end
end
def self.enshirt(input, output)
i = 0
output.print "redshirt2"
input.each_byte do |byte|
if byte > 0x20
i += 1
i %= 16
byte += TABLE(i)
if byte < 0x20
byte -= 0x5f
end
end
output.putc byte
end
end
def self.enshirtfile(filename)
if filename != nil and filename.length > 0 and filename != "-"
begin
File.open(filename, 'r') do |file|
enshirt(file, STDOUT)
end
rescue Errno::ENOENT
STDERR.puts "Error: Unable to open file `#{filename}'"
exit 1
end
else
enshirt(STDIN, STDOUT)
end
end
end
if ARGV(0) == '-e'
Redshirt.enshirtfile(ARGV(1))
elsif ARGV(0) == '-d'
Redshirt.deshirtfile(ARGV(1))
else
print <<END
Usage: #{File.basename $0} (-e|-d) (filename)
-e Encrypts the given file
-d Decrypts the given file
This script encrypts or decrypts a file with the redshirt2 algorithm.
The resulting text is printed on stdout.
If you pass no filename or a -, it reads from stdin instead of the file.
END
end
Simply paste that into a new file (I called mine "redshirt2.rb"), mark it executable, and run it. Or don't mark it executable and run it through the ruby interpreter yourself (i.e. `ruby redshirt2.rb -d game.txt). Run the script with no arguments to get a short help text.
I hope this is useful to someone.
-Eridius
This post has been edited by Aranor : 07 April 2005 - 01:12 PM