Skip to content

riencryptlib

This library scrambles any block of memory with a simple cipher and restores it again. The cipher has three “wheels”, byte values from 0 to 255 that step on like an odometer: before each byte, wheel 1 moves on by one, wheel 2 when wheel 1 wraps round, and wheel 3 when wheel 2 wraps round; the sum of the three wheels is added to the byte.

Encrypt starts from wheel positions you give, or from random ones. To decrypt the block, Decrypt needs the positions the wheels stopped at, which GetWheel tells after Encrypt: keep them, the data cannot be retrieved without them. The commands work in place, on memory the program provides, in Amiga and Blitz mode.

a$="A secret message"
l=Len(a$)
Encrypt &a$,l
w1=GetWheel(1) : w2=GetWheel(2) : w3=GetWheel(3)
Decrypt &a$,l,w1,w2,w3
NPrint a$

The fixed bugs of the library are listed in Fixes in riencryptlib.

Based on the RI Encrypt Lib guide by Reflective Images.

Library number 52.

Commands

Decrypt

Decrypts length bytes of memory from memadr on, in place, with the wheel positions that GetWheel returned after Encrypt. The wheels are not optional.

Statement. Help text: memadr,length,wheel1,wheel2,wheel3[,mode]
2 forms:

  • .l, .l, .w, .w, .w
  • .l, .l, .w, .w, .w, .w

With mode 1, the wheels are instead the start positions given to Encrypt, and the command works out the end positions from the length itself. A length of 0 changes nothing.

Encrypt

Encrypts length bytes of memory from memadr on, in place. The optional wheel1, wheel2 and wheel3, from 0 to 255, are the start positions of the wheels; without them the start positions are random.

Statement. Help text: memadr,length[,wheel1,wheel2,wheel3]
2 forms:

  • .l, .l
  • .l, .l, .w, .w, .w

Read the positions the wheels stopped at with GetWheel afterwards: Decrypt needs them. A length of 0 changes nothing.

GetWheel

The position, 0 to 255, of wheel 1, 2 or 3 after the last Encrypt or Decrypt; -1 for any other wheel number.

Function, result .w. Help text: wheel#
Arguments: .b