Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:36 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : CMM2: XXTEA file encryption with 'spcrypt'

Author Message
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 03:09pm 31 May 2021
Copy link to clipboard 
Print this post

Hi folks,

I'm not sure why you'd want to, but with 'spcrypt' you can do XXTEA/CBC/PKCS#7 encryption/decryption of files - or at least that's what I'm saying it does until someone who knows more about encryption can tell me otherwise.

400MHz Colour Maximite 2
MMBasic Version 5.07.00b33
Copyright 2011-2021 Geoff Graham
Copyright 2016-2021 Peter Mather

> *cd sptools/src/spcrypt
> *spcrypt
spcrypt: no command specified

Usage *spcrypt [OPTION]... <command> "input file" ["output file"]

Options:
 -p, --password=<password>  Use <password> for encryption/decryption.
                            If omitted then user will be prompted.
 --version                  Output version information and exit.

Commands:
 decrypt  Decrypt "input file" using XXTEA algorithm.
 encrypt  Encrypt "input file" using XXTEA algorithm.
 md5      Calculate MD5 checksum for "input file".

> *spcrypt md5 spcrypt.bas
7ed827543e2e6cbb3aa00c19562dcb76
OK

> *spcrypt encrypt -p=wombat spcrypt.bas
Overwrite existing 'spcrypt.bas.encrypt' [y|N] ? y
Encrypting from 'spcrypt.bas' to 'spcrypt.bas.encrypt' ...
OK

> *spcrypt decrypt -p=wombat spcrypt.bas.encrypt
Overwrite existing 'spcrypt.bas.encrypt.decrypt' [y|N] ? y
Decrypting from 'spcrypt.bas.encrypt' to 'spcrypt.bas.encrypt.decrypt' ...
OK


spcrypt.zip

Notes:

1. This above .zip contains a "flattened" version of the source with all the dependencies (and some other random stuff it doesn't depend on) inlined, if you want to read the code I'd check my github repo for the original source instead:

   - https://github.com/thwill1000/sptools/blob/develop-r1b3/src/spcrypt/spcrypt.bas
   - https://github.com/thwill1000/sptools/blob/develop-r1b3/src/splib/crypt.inc

2. 'spcrypt' uses a random initialisation vector, so if you encrypt the same file twice you get two different output files, both of which should decrypt to the original file.

3. Whilst almost certainly "better" than any adhoc encryption this isn't on a par with AES-256. I'm using MD5 to convert a password to a 128-bit key, which isn't particularly recommended (https://en.wikipedia.org/wiki/MD5) and XXTEA is also not the most secure (https://en.wikipedia.org/wiki/XXTEA).

Best wishes,

Tom
Edited 2021-06-01 01:11 by thwill
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2170
Posted: 07:30pm 31 May 2021
Copy link to clipboard 
Print this post

or this...

http://www.fruitoftheshed.com/MMBasic.RC4-Encryption-and-Decryption-Functions.ashx
Edited 2021-06-01 05:32 by CaptainBoing
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 07:54pm 31 May 2021
Copy link to clipboard 
Print this post

  CaptainBoing said  or this...

http://www.fruitoftheshed.com/MMBasic.RC4-Encryption-and-Decryption-Functions.ashx


Thanks Captain,

Indeed, I was aware of this implementation and it is undoubtedly faster but I would have learnt a great deal less. It's an obsolete stream cipher as opposed to an obsolete block cipher and the implementation provided doesn't have quite the bells and whistles supplied by spcrypt.

Best wishes,

Tom
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025