Category:Encryption/add-sub

From aldeid
Jump to navigation Jump to search
You are here
add & sub

Description

  • add and sub state for addition and substraction
  • add and sub are not reversible. They need to be used in tandem (one to encode and the other to decode).

Example

Asssembly

add byte ptr [edx], 0xa3
sub byte ptr [edx], 0xbc
cmp byte ptr [edx], 0x7d

Reversing

     ENCODING                 DECODING
┌─────────────────┐      ┌─────────────────┐
│ initial letter? │      │        p        │
└─────────────────┘      └─────────────────┘
        │ ord(letter)             ▲
        ▼                         │ chr(112 % 256)
┌─────────────────┐      ┌─────────────────┐
│ initial ordinal │      │       112       │
└─────────────────┘      └─────────────────┘
        │ add 0xa3                ▲
        ▼                         │ sub 0xa3
┌─────────────────┐      ┌─────────────────┐
│ initial value?  │      │       275       │
└─────────────────┘      └─────────────────┘
        │ sub 0xbc                ▲
        ▼                         │ add 0xbc
┌─────────────────┐      ┌─────────────────┐
│  result = 0x57  │ ───► │       0x57      │
└─────────────────┘      └─────────────────┘

The decryption can be performed in python as follows:

>>> chr((0x57 + 0xbc - 0xa3) % 256)
'p'

Pages in category "Encryption/add-sub"

The following 4 pages are in this category, out of 4 total.