You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

191 lines
5.6 KiB

2 years ago
.include "instr.inc"
.text
.global _start
_start:
# Get the address of the start of the program
push_pc
pop_r3
# Display the introduction
ld_r2_r3
add_r2 (str_intro - _start)
push_r3
call PrintStr
pop_r3
# Bail if we're not running from the correct address
cp_r3 _start
jp_eq main
ld_r2_r3
add_r2 (str_wrong_address - _start)
jp PrintStr
main:
# Gather the password string
ld_r2 mem_input
ld_r1 18
ld_r0 0
call MemSet
ld_r2 str_password_prompt
call PrintStr
ld_r2 mem_input
ld_r3 15
call ReadStr
ld_r2 mem_input
call StrTrim
# Hash the string
ld_r2 mem_input
ld_r0 0x9fc0
hash_loop:
ldr_r1_r2
inc_r2
cp_r1 0
# r0 = (((r0 * 2) ^ r1) * 2) + r1
shl_r0
xor_r0_r1
shl_r0
add_r0_r1
jp_eq decrypt
jp hash_loop
decrypt:
# Initialize memory
str_r0 mem_hash
ld_r3 mem_encrypted
ld_r2 mem_decrypted
ld_r1 0x200
call MemCpy
# Decrypt the entire buffer
ld_r2 mem_decrypted
ld_r3 0x200 / 2
decrypt_loop:
call update_hash
# *r2 -= mem_hash
ld_r1_r0
ldr_r0_r2
xor_r0_r1
str_r0_r2
inc_r2
inc_r2
dec_r3
cp_r3 0
jp_ne decrypt_loop
# Print out the results
ld_r2 str_result_start
call PrintStr
ld_r2 mem_decrypted
call PrintStr
ld_r2 str_result_end
call PrintStr
ret
update_hash:
# mem_hash = (mem_hash * 0x41a7) ^ 0x5555
ldr_r0 mem_hash
mul_r0 0x41a7
xor_r0 0x5555
str_r0 mem_hash
ret
str_intro:
.ascii "GLITCH RESEARCH LABORATORY SELF-CONTAINED ENCRYPTION TOOL\n\0"
str_wrong_address:
.ascii "PLEASE LOAD ME AT ADDRESS $2000... (EXITING)\n\0"
str_password_prompt:
.ascii "PLEASE ENTER ENCRYPTION PASSWORD: \0"
str_result_start:
.ascii "HERE IS THE ENCRYPTED DOCUMENT: "
str_result_end:
.ascii "\n--\n\0"
mem_input:
.ascii "________________\0\0"
mem_hash:
.ascii "__"
# Padding
.ascii "33333333"
mem_encrypted:
.byte 0xfb, 0x72, 0x3a, 0x22, 0x21, 0x4b, 0x6a, 0xc2
.byte 0x28, 0xe6, 0xe4, 0xc1, 0xa7, 0x25, 0xb6, 0xe0
.byte 0x98, 0xb2, 0x0a, 0xe0, 0x9b, 0xab, 0xc1, 0x84
.byte 0xb8, 0x2d, 0x8f, 0xd8, 0x7e, 0x07, 0x3a, 0xcb
.byte 0xc9, 0xf0, 0xf5, 0x38, 0x51, 0x43, 0xed, 0x52
.byte 0xf8, 0x44, 0xe4, 0xc2, 0x50, 0x22, 0x27, 0x2a
.byte 0x65, 0x44, 0x81, 0x79, 0xc2, 0x6c, 0xb4, 0xaf
.byte 0xd9, 0x9d, 0x7c, 0x74, 0xb3, 0x58, 0xea, 0xcd
.byte 0x69, 0xe2, 0xa2, 0xdf, 0xe7, 0xca, 0xc4, 0x65
.byte 0xe0, 0xe8, 0xf3, 0xbe, 0xee, 0x97, 0x68, 0xad
.byte 0x61, 0x0e, 0x27, 0x78, 0x32, 0x86, 0x6d, 0x5c
.byte 0x02, 0xc2, 0x6e, 0xd1, 0xdf, 0x93, 0x14, 0x4d
.byte 0xcb, 0x1a, 0x90, 0xf4, 0x20, 0x95, 0xc0, 0xd3
.byte 0x1d, 0xe8, 0x73, 0x2b, 0xdb, 0xaf, 0xae, 0x74
.byte 0x7a, 0x1d, 0x50, 0x4a, 0xa6, 0x9d, 0x56, 0xcc
.byte 0xb5, 0x5d, 0x07, 0xd1, 0x04, 0xa7, 0x16, 0x5c
.byte 0x1d, 0x40, 0x4e, 0x65, 0x51, 0xf2, 0x68, 0x0a
.byte 0x4a, 0xb3, 0x56, 0x56, 0xc1, 0x51, 0x1f, 0x0f
.byte 0xc2, 0x7d, 0x4b, 0x29, 0x5b, 0x58, 0x1d, 0x2f
.byte 0xff, 0x66, 0xc0, 0x3c, 0xbb, 0xbb, 0x34, 0x93
.byte 0x30, 0xe6, 0x34, 0xb7, 0x8d, 0xd4, 0x4a, 0xa3
.byte 0xd7, 0x88, 0x00, 0x72, 0xba, 0x13, 0x0c, 0x4d
.byte 0x97, 0x46, 0xe0, 0xbb, 0x07, 0xa6, 0xef, 0xfa
.byte 0x12, 0x0a, 0xfe, 0x56, 0xe9, 0x14, 0x2b, 0xda
.byte 0x64, 0x3c, 0xfe, 0xc5, 0x3c, 0xa3, 0x50, 0x02
.byte 0x20, 0xb7, 0x20, 0x05, 0x3d, 0xdb, 0xf1, 0x8a
.byte 0x81, 0x41, 0x4c, 0x24, 0x52, 0x38, 0x8f, 0xb9
.byte 0x7e, 0x2e, 0x6f, 0x76, 0x1c, 0x3f, 0x97, 0x87
.byte 0x16, 0xd5, 0xd3, 0xc9, 0x70, 0x92, 0xd7, 0xd2
.byte 0x47, 0x59, 0xe6, 0x87, 0x12, 0x2c, 0xe0, 0xa5
.byte 0x6c, 0x17, 0x9c, 0xbe, 0xee, 0xe4, 0xd4, 0x50
.byte 0xea, 0x94, 0x57, 0x91, 0x4f, 0xb1, 0x57, 0xaa
.byte 0x46, 0xe9, 0x86, 0x76, 0xd3, 0xf8, 0xb9, 0xa5
.byte 0x8c, 0x9c, 0x57, 0x56, 0x0a, 0x72, 0x48, 0xc8
.byte 0x14, 0xb6, 0x8b, 0xf2, 0x48, 0x3c, 0x4d, 0xb5
.byte 0x3a, 0x48, 0x07, 0xa6, 0xf2, 0x8e, 0xa3, 0x0b
.byte 0x39, 0x02, 0x75, 0x9b, 0xc8, 0xdc, 0x6f, 0x0a
.byte 0x75, 0x00, 0x52, 0x6d, 0xbf, 0x77, 0x89, 0x2f
.byte 0xce, 0xb0, 0x27, 0xef, 0x42, 0x1e, 0x36, 0xe1
.byte 0x37, 0xc6, 0xf7, 0x77, 0x34, 0x1d, 0x6a, 0xd3
.byte 0xa7, 0x48, 0x6a, 0xc1, 0x7d, 0xe7, 0x76, 0x8c
.byte 0x62, 0x8f, 0x62, 0x8c, 0x5c, 0xe4, 0xf1, 0xf3
.byte 0xfd, 0x5f, 0xb6, 0x9d, 0xb4, 0xd7, 0xa8, 0xa0
.byte 0xcd, 0xde, 0x8b, 0x72, 0x73, 0xe4, 0xfa, 0xe7
.byte 0x33, 0x8f, 0x11, 0x1e, 0xaf, 0xd3, 0x40, 0xa7
.byte 0x86, 0x26, 0xf3, 0x77, 0x4c, 0x6e, 0x2d, 0x2d
.byte 0xa4, 0x03, 0xc2, 0x74, 0x2e, 0xb3, 0xdd, 0x85
.byte 0x29, 0x41, 0x90, 0xc3, 0xc7, 0x3a, 0x96, 0xb9
.byte 0x8e, 0x35, 0xcf, 0x37, 0xc0, 0xc8, 0xff, 0xd5
.byte 0x8b, 0x9f, 0xa1, 0xd9, 0x0f, 0x8e, 0x8e, 0xc6
.byte 0x11, 0xc1, 0xc0, 0xc9, 0x9e, 0x5b, 0x9c, 0xa1
.byte 0x2d, 0xc6, 0x4b, 0xf5, 0x34, 0x65, 0xb4, 0xcc
.byte 0xac, 0x88, 0xbf, 0x49, 0x43, 0x77, 0xac, 0x8f
.byte 0x61, 0x71, 0x8e, 0x59, 0x7f, 0x78, 0xd9, 0x73
.byte 0x41, 0x90, 0x73, 0x8b, 0x8e, 0x93, 0x3f, 0x6e
.byte 0xdd, 0x2e, 0x37, 0xe8, 0x72, 0x43, 0xa1, 0xf3
.byte 0xa9, 0xfe, 0x7f, 0x98, 0xf3, 0xa5, 0x98, 0x43
.byte 0xe5, 0x60, 0xb9, 0x5d, 0xbd, 0xba, 0x3f, 0xae
.byte 0x71, 0xf6, 0xed, 0xc1, 0xfe, 0x8f, 0x2d, 0x15
.byte 0xd9, 0xc6, 0xf7, 0x57, 0x83, 0x57, 0x7e, 0x10
.byte 0xb6, 0xc3, 0x76, 0x29, 0xb1, 0x10, 0x12, 0x1e
.byte 0xea, 0xa1, 0x15, 0x81, 0x9c, 0x22, 0x5f, 0x8a
.byte 0xf3, 0xff, 0x1c, 0x37, 0x4e, 0x57, 0x1b, 0x26
.byte 0x64, 0xb7, 0xca, 0x7c, 0xc8, 0x57, 0xd9, 0x57
mem_decrypted:
.fill 0x200, 1, 0