Re: lun - Lucky Number

Liste des GroupesRevenir à s crypt 
Sujet : Re: lun - Lucky Number
De : rjh (at) *nospam* cpax.org.uk (Richard Heathfield)
Groupes : sci.crypt
Date : 12. Mar 2025, 13:32:51
Autres entêtes
Organisation : Fix this later
Message-ID : <vqrutj$2jmr5$1@dont-email.me>
References : 1 2 3 4 5 6 7
User-Agent : Mozilla Thunderbird
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 Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within

Date Sujet#  Auteur
8 Mar 25 * lun - Lucky Number44Stefan Claas
8 Mar 25 +* Re: lun - Lucky Number2Stefan Claas
8 Mar 25 i`- Re: lun - Lucky Number1Stefan Claas
8 Mar 25 `* Re: lun - Lucky Number41Rich
8 Mar 25  +* Re: lun - Lucky Number38Stefan Claas
8 Mar 25  i+* Re: lun - Lucky Number14Stefan Claas
8 Mar 25  ii+* Re: lun - Lucky Number2Richard Heathfield
8 Mar 25  iii`- Re: lun - Lucky Number1Stefan Claas
8 Mar 25  ii`* Re: lun - Lucky Number11Rich
8 Mar 25  ii `* Re: lun - Lucky Number10Richard Heathfield
9 Mar 25  ii  `* Re: lun - Lucky Number9Rich
9 Mar 25  ii   +- Re: lun - Lucky Number1Richard Heathfield
10 Mar 25  ii   +- Re: lun - Lucky Number1Chris M. Thomasson
11 Mar 25  ii   `* Re: lun - Lucky Number6Ben Bacarisse
11 Mar 25  ii    `* Re: lun - Lucky Number5Rich
11 Mar 25  ii     `* Re: lun - Lucky Number4Richard Heathfield
11 Mar 25  ii      +* Re: lun - Lucky Number2Rich
11 Mar 25  ii      i`- Re: lun - Lucky Number1Richard Harnden
11 Mar 25  ii      `- Re: lun - Lucky Number1Chris M. Thomasson
8 Mar 25  i+* Re: lun - Lucky Number19Richard Heathfield
8 Mar 25  ii`* Re: lun - Lucky Number18Stefan Claas
8 Mar 25  ii +* Re: lun - Lucky Number2Chris M. Thomasson
8 Mar 25  ii i`- Re: lun - Lucky Number1Chris M. Thomasson
9 Mar 25  ii `* Re: lun - Lucky Number15Richard Heathfield
9 Mar 25  ii  `* Re: lun - Lucky Number14Stefan Claas
9 Mar 25  ii   +* Re: lun - Lucky Number3Stefan Claas
9 Mar 25  ii   i`* Re: lun - Lucky Number2Stefan Claas
9 Mar 25  ii   i `- Re: lun - Lucky Number1Stefan Claas
12 Mar 25  ii   `* Re: lun - Lucky Number10Richard Heathfield
15 Mar 25  ii    `* Re: lun - Lucky Number9Marcel Logen
15 Mar 25  ii     `* Re: lun - Lucky Number8Richard Heathfield
16 Mar 25  ii      `* Re: lun - Lucky Number7Marcel Logen
16 Mar 25  ii       `* Re: lun - Lucky Number6Richard Heathfield
16 Mar 25  ii        `* Re: lun - Lucky Number5Marcel Logen
16 Mar 25  ii         `* Re: lun - Lucky Number4Richard Heathfield
16 Mar 25  ii          `* Re: lun - Lucky Number3Marcel Logen
17 Mar 25  ii           `* Re: lun - Lucky Number2Richard Heathfield
17 Mar 25  ii            `- Re: lun - Lucky Number1Marcel Logen
8 Mar 25  i`* Re: lun - Lucky Number4Rich
8 Mar 25  i `* Re: lun - Lucky Number3Marcel Logen
9 Mar 25  i  `* Re: lun - Lucky Number2Rich
9 Mar 25  i   `- Re: lun - Lucky Number1Marcel Logen
8 Mar 25  `* Re: lun - Lucky Number2Richard Heathfield
8 Mar 25   `- Re: lun - Lucky Number1Chris M. Thomasson

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal