Skip to main content
Bumped by Community user
Tweeted twitter.com/StackReverseEng/status/1589679083985653761
added 1 character in body; edited title
Source Link
0xC0000022L
  • 10.9k
  • 9
  • 41
  • 79

Simplifying and reversing an encryption/decryption algorythnalgorithm in ASM X86 / Python

I'm trying to reverse a decoding function in order to produce the function for encoding (for the curious this is a save game for a legacy adventure game wichwhich use codes for saving).

Simplifying and reversing an encryption/decryption algorythn in ASM X86 / Python

I'm trying to reverse a decoding function in order to produce the function for encoding (for the curious this is a save game for a legacy adventure game wich use codes for saving).

Simplifying and reversing an encryption/decryption algorithm in ASM X86 / Python

I'm trying to reverse a decoding function in order to produce the function for encoding (for the curious this is a save game for a legacy adventure game which use codes for saving).

added 17 characters in body
Source Link
Simon
  • 31
  • 2
def load_and_decode_value(text, index, table):
  current_char = ord(text[index])
  return table[current_char]

def text_to_hex(text):
  with open("DECODE_TABLE.bin", mode='rb') as file:
    DECODE_TABLE = file.read()

  decoded = []
  val_indexchar_index = 0
  text_len = len(text)

  for i in range(0, 5):

    val_0 = load_and_decode_value(text, val_indexchar_index, DECODE_TABLE)
    val_indexchar_index += 1
    val_1 = load_and_decode_value(text, val_indexchar_index, DECODE_TABLE)
    val_indexchar_index += 1
    val_next_0 = (val_0 * 2048) | (val_1 * 64)
    val_1 = (val_next_0 // 256) & 0xFF
    decoded.append(val_1)

    if i == 4:
      break

    val_2 = load_and_decode_value(text, val_indexchar_index, DECODE_TABLE)
    val_indexchar_index += 1
    val_3 = load_and_decode_value(text, val_indexchar_index, DECODE_TABLE)
    val_indexchar_index += 1
    val_next_1 = (((val_2 * 2) | val_next_0) * 16777216) | (val_3 * 1048576)
    val_3 = (val_next_1 // 16777216) & 0xFF
    decoded.append(val_3)

    val_4 = load_and_decode_value(text, val_indexchar_index, DECODE_TABLE)
    val_indexchar_index += 1
    val_next_2 = val_next_1 | (val_4 * 32768)
    val_4 = (val_next_2 // 65536) & 0xFF
    decoded.append(val_4)

    val_5 = load_and_decode_value(text, val_indexchar_index, DECODE_TABLE)
    val_indexchar_index += 1
    val_6 = load_and_decode_value(text, val_indexchar_index, DECODE_TABLE)
    val_indexchar_index += 1
    val_next_2 = val_next_2 | (val_5 * 1024)
    val_next_3 = val_next_2 | (val_6 * 32)
    val_6 = (val_next_3 // 256) & 0xFF
    decoded.append(val_6)

    val_7 = load_and_decode_value(text, val_indexchar_index, DECODE_TABLE)
    val_indexchar_index += 1
    val_8 = (val_next_3 | val_7) & 0xFF 
    decoded.append(val_8)

  return decoded
def load_and_decode_value(text, index, table):
  current_char = ord(text[index])
  return table[current_char]

def text_to_hex(text):
  with open("DECODE_TABLE.bin", mode='rb') as file:
    DECODE_TABLE = file.read()

  decoded = []
  val_index = 0
  text_len = len(text)

  for i in range(0, 5):

    val_0 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_1 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_next_0 = (val_0 * 2048) | (val_1 * 64)
    val_1 = (val_next_0 // 256) & 0xFF
    decoded.append(val_1)

    if i == 4:
      break

    val_2 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_3 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_next_1 = (((val_2 * 2) | val_next_0) * 16777216) | (val_3 * 1048576)
    val_3 = (val_next_1 // 16777216) & 0xFF
    decoded.append(val_3)

    val_4 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_next_2 = val_next_1 | (val_4 * 32768)
    val_4 = (val_next_2 // 65536) & 0xFF
    decoded.append(val_4)

    val_5 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_6 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_next_2 = val_next_2 | (val_5 * 1024)
    val_next_3 = val_next_2 | (val_6 * 32)
    val_6 = (val_next_3 // 256) & 0xFF
    decoded.append(val_6)

    val_7 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_8 = (val_next_3 | val_7) & 0xFF 
    decoded.append(val_8)

  return decoded
def load_and_decode_value(text, index, table):
  current_char = ord(text[index])
  return table[current_char]

def text_to_hex(text):
  with open("DECODE_TABLE.bin", mode='rb') as file:
    DECODE_TABLE = file.read()

  decoded = []
  char_index = 0
  text_len = len(text)

  for i in range(0, 5):

    val_0 = load_and_decode_value(text, char_index, DECODE_TABLE)
    char_index += 1
    val_1 = load_and_decode_value(text, char_index, DECODE_TABLE)
    char_index += 1
    val_next_0 = (val_0 * 2048) | (val_1 * 64)
    val_1 = (val_next_0 // 256) & 0xFF
    decoded.append(val_1)

    if i == 4:
      break

    val_2 = load_and_decode_value(text, char_index, DECODE_TABLE)
    char_index += 1
    val_3 = load_and_decode_value(text, char_index, DECODE_TABLE)
    char_index += 1
    val_next_1 = (((val_2 * 2) | val_next_0) * 16777216) | (val_3 * 1048576)
    val_3 = (val_next_1 // 16777216) & 0xFF
    decoded.append(val_3)

    val_4 = load_and_decode_value(text, char_index, DECODE_TABLE)
    char_index += 1
    val_next_2 = val_next_1 | (val_4 * 32768)
    val_4 = (val_next_2 // 65536) & 0xFF
    decoded.append(val_4)

    val_5 = load_and_decode_value(text, char_index, DECODE_TABLE)
    char_index += 1
    val_6 = load_and_decode_value(text, char_index, DECODE_TABLE)
    char_index += 1
    val_next_2 = val_next_2 | (val_5 * 1024)
    val_next_3 = val_next_2 | (val_6 * 32)
    val_6 = (val_next_3 // 256) & 0xFF
    decoded.append(val_6)

    val_7 = load_and_decode_value(text, char_index, DECODE_TABLE)
    char_index += 1
    val_8 = (val_next_3 | val_7) & 0xFF 
    decoded.append(val_8)

  return decoded
added 9 characters in body
Source Link
Simon
  • 31
  • 2
def load_and_decode_value(text, index, table):
  current_char = ord(text[index])
  return table[current_char]

def text_to_hex(text):
  with open("DECODE_TABLE.bin", mode='rb') as file:
    DECODE_TABLE = file.read()

  decoded = []
  val_index = 0
  text_len = len(text)

  for i in range(0, 5):

    val_0 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_1 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_next_0 = (val_0 * 2048) | (val_1 * 64)
    val_1 = (val_next_0 >>// 8256) & 0xFF
    decoded.append(val_1)

    if i == 4:
      break

    val_2 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_3 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_next_1 = (((val_2 * 2) | val_next_0) * 16777216) | (val_3 * 1048576)
    val_3 = (val_next_1 >>// 0x1816777216) & 0xFF
    decoded.append(val_3)

    val_4 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_next_2 = val_next_1 | (val_4 * 32768)
    val_4 = (val_next_2 >>// 0x1065536) & 0xFF
    decoded.append(val_4)

    val_5 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_6 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_next_2 = val_next_2 | (val_5 * 1024)
    val_next_3 = val_next_2 | (val_6 * 32)
    val_6 = (val_next_3 >>// 8256) & 0xFF
    decoded.append(val_6)

    val_7 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_8 = (val_next_3 | val_7) & 0xFF 
    decoded.append(val_8)

  return decoded
def load_and_decode_value(text, index, table):
  current_char = ord(text[index])
  return table[current_char]

def text_to_hex(text):
  with open("DECODE_TABLE.bin", mode='rb') as file:
    DECODE_TABLE = file.read()

  decoded = []
  val_index = 0
  text_len = len(text)

  for i in range(0, 5):

    val_0 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_1 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_next_0 = (val_0 * 2048) | (val_1 * 64)
    val_1 = (val_next_0 >> 8) & 0xFF
    decoded.append(val_1)

    if i == 4:
      break

    val_2 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_3 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_next_1 = (((val_2 * 2) | val_next_0) * 16777216) | (val_3 * 1048576)
    val_3 = (val_next_1 >> 0x18) & 0xFF
    decoded.append(val_3)

    val_4 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_next_2 = val_next_1 | (val_4 * 32768)
    val_4 = (val_next_2 >> 0x10) & 0xFF
    decoded.append(val_4)

    val_5 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_6 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_next_2 = val_next_2 | (val_5 * 1024)
    val_next_3 = val_next_2 | (val_6 * 32)
    val_6 = (val_next_3 >> 8) & 0xFF
    decoded.append(val_6)

    val_7 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_8 = (val_next_3 | val_7) & 0xFF 
    decoded.append(val_8)

  return decoded
def load_and_decode_value(text, index, table):
  current_char = ord(text[index])
  return table[current_char]

def text_to_hex(text):
  with open("DECODE_TABLE.bin", mode='rb') as file:
    DECODE_TABLE = file.read()

  decoded = []
  val_index = 0
  text_len = len(text)

  for i in range(0, 5):

    val_0 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_1 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_next_0 = (val_0 * 2048) | (val_1 * 64)
    val_1 = (val_next_0 // 256) & 0xFF
    decoded.append(val_1)

    if i == 4:
      break

    val_2 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_3 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_next_1 = (((val_2 * 2) | val_next_0) * 16777216) | (val_3 * 1048576)
    val_3 = (val_next_1 // 16777216) & 0xFF
    decoded.append(val_3)

    val_4 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_next_2 = val_next_1 | (val_4 * 32768)
    val_4 = (val_next_2 // 65536) & 0xFF
    decoded.append(val_4)

    val_5 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_6 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_next_2 = val_next_2 | (val_5 * 1024)
    val_next_3 = val_next_2 | (val_6 * 32)
    val_6 = (val_next_3 // 256) & 0xFF
    decoded.append(val_6)

    val_7 = load_and_decode_value(text, val_index, DECODE_TABLE)
    val_index += 1
    val_8 = (val_next_3 | val_7) & 0xFF 
    decoded.append(val_8)

  return decoded
Edited my code
Source Link
Simon
  • 31
  • 2
Loading
deleted 897 characters in body
Source Link
Simon
  • 31
  • 2
Loading
added 174 characters in body
Source Link
Simon
  • 31
  • 2
Loading
deleted 47 characters in body
Source Link
Simon
  • 31
  • 2
Loading
deleted 259 characters in body
Source Link
Simon
  • 31
  • 2
Loading
added 92 characters in body
Source Link
Simon
  • 31
  • 2
Loading
added 1 character in body
Source Link
Simon
  • 31
  • 2
Loading
added 380 characters in body
Source Link
Simon
  • 31
  • 2
Loading
deleted 186 characters in body
Source Link
Simon
  • 31
  • 2
Loading
deleted 2060 characters in body
Source Link
Simon
  • 31
  • 2
Loading
deleted 296 characters in body
Source Link
Simon
  • 31
  • 2
Loading
added 89 characters in body
Source Link
Simon
  • 31
  • 2
Loading
added 2007 characters in body
Source Link
Simon
  • 31
  • 2
Loading
Updated code
Source Link
Simon
  • 31
  • 2
Loading
added 47 characters in body
Source Link
Simon
  • 31
  • 2
Loading
Fixed a bug in the code example (again).
Source Link
Simon
  • 31
  • 2
Loading
Fixed a bug in the code example.
Source Link
Simon
  • 31
  • 2
Loading
Added content of data file
Source Link
Simon
  • 31
  • 2
Loading
added 44 characters in body
Source Link
Simon
  • 31
  • 2
Loading
Source Link
Simon
  • 31
  • 2
Loading