On 09/03/2025 10:21, Stefan Claas wrote:
Richard Heathfield wrote:
On 08/03/2025 19:11, Stefan Claas wrote:
Well, Rich (and maybe you) should also show things to the community here,
which can be discussed, otherwise this place is getting pretty boring.
>
Okay. How about a new primitive? (I /think/ it's new, but of course
there's nothing new under the sun so I might be mistaken.)
>
Take 8 consecutive bytes, imagine them as a square of 8x8 bits, and
'tumbleweed' the bits clockwise.
>
That is, turn this:
>
abcdefgh
ijklmnop
qrstuvwx
yzABCDEF
GHIJKLMN
OPQRSTUV
WXYZ0123
456789+=
>
to this:
>
4WOGyqia
5XPHzrjb
6YQIAskc
7ZRJBtld
80SKCume
91TLDvnf
+2UMEwog
=3VNFxph
>
The inverse is of course to tumbleweed them anticlockwise.
>
Sort of gives a new spin to bit rotation.
>
This is a really nice idea! :-)
Jolly kind of you, but the idea you read isn't the idea I wrote.
Where I wrote "bit" you appear to have read "byte".
That's fine --- it's perfectly workable at the byte level --- but my idea was to incorporate it into cryptosystems that encrypt at the bit level.
If you're Feistelising you can throw this in pretty much anywhere, but if you're decrypting the long way you obviously match each left tumble out with a right tumble in, and a right tumble out with a left tumble in.
If you don't like padding but have always wondered about how to encrypt those last few bytes of the plaintext that don't quite fit in a block, this could be quite a neat way to spin those end bits into the fold and give them a bit of a mash.
Tell you what, I'll let my source code do the talking and give you a demo run at the end:
tuwetest.c: gcc -o tuwetest tuwetest.c tuwe.c
#include "tuwe.h"
#include <stdio.h>
static void dump(const void *vb, int n)
{
int i = 0;
int j = 0;
const unsigned char * b = vb;
for(i = 0; i < n; i++)
{
for(j = 7; j >= 0; j--)
{
fprintf(stdout, "%d", !!(b[i] & (1 << j)));
}
putchar('\n');
}
printf("--------\n");
}
int main(void)
{
unsigned char t[8] = {31, 41, 59, 26, 53, 58, 97, 32};
unsigned char r[8] = {0, 0, 0, 0, 0, 0, 0, 0};
unsigned char l[8] = {0, 0, 0, 0, 0, 0, 0, 0};
puts("t first");
dump(t, 8);
puts("now turn it right 90 deg");
tuwer(r, t);
dump(r, 8);
puts("and back again");
tuwel(l, r);
dump(t, 8);
return 0;
}
tuwe.h:
#ifndef TUWE_H_
#define TUWE_H_ 1
void tuwer(void *vout, const void *vin);
void tuwel(void *vout, const void *vin);
#endif
tuwe.c:
/* Tumbleweed */
/* Posted to sci.crypt by Richard Heathfield in March 2025
*
* rotate 64 bits clockwise one quarter turn (tuwer) or
* anticlockwise one quarter turn (tuwel).
*
* abcdefgh
* ijklmnop
* qrstuvwx
* yzABCDEF
* GHIJKLMN
* OPQRSTUV
* WXYZ0123
* 456789+=
*
* to
*
* 4WOGyqia
* 5XPHzrjb
* 6YQIAskc
* 7ZRJBtld
* 80SKCume
* 91TLDvnf
* +2UMEwog
* =3VNFxph
*
* and versa vice */
#include "tuwe.h"
#define BIT_QRY(x,i) ((x[(i)>>3] & (1<<((i)&7)))!=0)
#define BIT_SET(x,i) (x)[(i)>>3]|=(1<<((i)&7))
#define BIT_CLR(x,i) (x)[(i)>>3]&=(1<<((i)&7))^0xFF
void tuwer(void *vout, const void *vin)
{
const unsigned char *in = vin;
unsigned char *out = vout;
int src = 0;
int tgt = 0;
int byte = 0;
int bit = 0;
int val = 0;
for(byte = 0; byte < 8; byte++)
{
for(bit = 0; bit < 8; bit++)
{
src = ((byte<<3)|bit);
val = BIT_QRY(in, src);
tgt = ((7-bit)<<3)|byte;
if(val)
{
BIT_SET(out, tgt);
}
else
{
BIT_CLR(out, tgt);
}
}
}
}
void tuwel(void *vout, const void *vin)
{
const unsigned char *in = vin;
unsigned char *out = vout;
int src = 0;
int tgt = 0;
int byte = 0;
int bit = 0;
int val = 0;
for(byte = 0; byte < 8; byte++)
{
for(bit = 0; bit < 8; bit++)
{
src = ((byte<<3)|bit);
val = BIT_QRY(in, src);
tgt = (bit<<3)|(7-byte);
if(val)
{
BIT_SET(out, tgt);
}
else
{
BIT_CLR(out, tgt);
}
}
}
}
Demo run:
t first
00011111
00101001
00111011
00011010
00110101
00111010
01100001
00100000
--------
now turn it right 90 deg
00000000
01000000
11110110
00111101
00101111
00010001
00101101
01010111
--------
and back again
00011111
00101001
00111011
00011010
00110101
00111010
01100001
00100000
--------
-- Richard HeathfieldEmail: rjh at cpax dot org dot uk"Usenet is a strange place" - dmr 29 July 1999Sig line 4 vacant - apply within