• lun - Lucky Number

    From Stefan Claas@21:1/5 to All on Sat Mar 8 01:43:30 2025
    Hi all,

    from the previous discussion with Richard I came up with a new idea to
    create a random number. I call the Go program lun = Lucky Number.

    Here is a sample run with 3 seconds set. You can also use1 or many more seconds.

    $ lun 3

    Started: 2025-03-08 01:29:57

    2287128966796887 1741393797 2287130708190684
    2443764953918824 1741393798 2443766695312622
    8241182675020522 1741393799 8241184416414321

    Ended: 2025-03-08 01:29:59
    Time elapsed: 00:00:03
    Multiplying: 2287130708190684 * 8241184416414321
    Your lucky number is: 18848665950643714819328816385564
    SHA256: 28fd1445771c772f403eb4092b722640a529b5c84c3ee50bc6d631454e83daed

    The first column is a random number, the second the local Unix-Epoch-Time
    and the third shows the addition of column1 and column2. The lucky number
    was generated by multiplying the first and last value of the right column.

    Hope you like the idea!

    Regards
    Stefan

    --
    Onion Courier Home Server Mon-Fri 15:00-21:00 UTC Sat-Sun 11:00-21:00 UTC ohpmsq5ypuw5nagt2jidfyq72jvgw3fdvq37txhnm5rfbhwuosftzuyd.onion:8080 inbox
    age1yubikey1qv5z678j0apqhd4ng7p22g4da8vxy3q5uvthg6su76yj0y8v7wp5kvhstum

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Claas@21:1/5 to Stefan Claas on Sat Mar 8 11:29:19 2025
    Stefan Claas wrote:

    Hi all,

    from the previous discussion with Richard I came up with a new idea to
    create a random number. I call the Go program lun = Lucky Number.

    Here is a sample run with 3 seconds set. You can also use1 or many more seconds.

    $ lun 3

    Started: 2025-03-08 01:29:57

    2287128966796887 1741393797 2287130708190684
    2443764953918824 1741393798 2443766695312622
    8241182675020522 1741393799 8241184416414321

    Ended: 2025-03-08 01:29:59
    Time elapsed: 00:00:03
    Multiplying: 2287130708190684 * 8241184416414321
    Your lucky number is: 18848665950643714819328816385564
    SHA256: 28fd1445771c772f403eb4092b722640a529b5c84c3ee50bc6d631454e83daed

    The first column is a random number, the second the local Unix-Epoch-Time
    and the third shows the addition of column1 and column2. The lucky number
    was generated by multiplying the first and last value of the right column.

    Hope you like the idea!

    Forgot the URL: https://github.com/706f6c6c7578/lun

    Regards
    Stefan

    --
    Onion Courier Home Server Mon-Fri 15:00-21:00 UTC Sat-Sun 11:00-21:00 UTC ohpmsq5ypuw5nagt2jidfyq72jvgw3fdvq37txhnm5rfbhwuosftzuyd.onion:8080 inbox
    age1yubikey1qv5z678j0apqhd4ng7p22g4da8vxy3q5uvthg6su76yj0y8v7wp5kvhstum

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Claas@21:1/5 to Stefan Claas on Sat Mar 8 18:26:28 2025
    Stefan Claas wrote:
    Stefan Claas wrote:

    Hi all,

    from the previous discussion with Richard I came up with a new idea to create a random number. I call the Go program lun = Lucky Number.

    Here is a sample run with 3 seconds set. You can also use1 or many more seconds.

    $ lun 3

    Started: 2025-03-08 01:29:57

    2287128966796887 1741393797 2287130708190684
    2443764953918824 1741393798 2443766695312622
    8241182675020522 1741393799 8241184416414321

    Ended: 2025-03-08 01:29:59
    Time elapsed: 00:00:03
    Multiplying: 2287130708190684 * 8241184416414321
    Your lucky number is: 18848665950643714819328816385564
    SHA256: 28fd1445771c772f403eb4092b722640a529b5c84c3ee50bc6d631454e83daed

    The first column is a random number, the second the local Unix-Epoch-Time and the third shows the addition of column1 and column2. The lucky number was generated by multiplying the first and last value of the right column.

    Hope you like the idea!

    Forgot the URL: https://github.com/706f6c6c7578/lun

    C code for Linux and Windows, plus binaries.

    Download link expires in 1 week!!!

    <https://limewire.com/d/3d1e74fe-462d-40e9-9aac-126eadfeb074#GCI__N-TLqrTZn5bWx-yZL15MibFzYg8VSGHB7zesuM>

    I think lun is a pretty cool little program. :-)

    Regards
    Stefan

    --
    Onion Courier Home Server Mon-Fri 15:00-21:00 UTC Sat-Sun 11:00-21:00 UTC ohpmsq5ypuw5nagt2jidfyq72jvgw3fdvq37txhnm5rfbhwuosftzuyd.onion:8080 inbox
    age1yubikey1qv5z678j0apqhd4ng7p22g4da8vxy3q5uvthg6su76yj0y8v7wp5kvhstum

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to Stefan Claas on Sat Mar 8 18:34:00 2025
    Stefan Claas <fgrsna.pynnf@vagrearg.eh> wrote:
    Hi all,

    from the previous discussion with Richard I came up with a new idea to
    create a random number. I call the Go program lun = Lucky Number.

    How /random/ do you want this number to be?

    Here is a sample run with 3 seconds set. You can also use1 or many
    more seconds.

    $ lun 3

    Started: 2025-03-08 01:29:57

    2287128966796887 1741393797 2287130708190684
    2443764953918824 1741393798 2443766695312622
    8241182675020522 1741393799 8241184416414321

    Ended: 2025-03-08 01:29:59
    Time elapsed: 00:00:03
    Multiplying: 2287130708190684 * 8241184416414321
    Your lucky number is: 18848665950643714819328816385564
    SHA256: 28fd1445771c772f403eb4092b722640a529b5c84c3ee50bc6d631454e83daed

    The first column is a random number

    So, you already have a *random number*. Why do any more?

    , the second the local Unix-Epoch-Time

    Very *not* random.

    and the third shows the addition of column1 and column2.

    Provided the random number was "good enough randomness" this has no
    benefit.

    The lucky number was generated by multiplying the first and last
    value of the right column.

    The product R1 * R2 is little different, randomness wise, from the
    product R1 * (R2 + Predictable_Offset). If you can generate random
    numbers, what is the value in computing R1 * (R2 + Predictable_Offset)?

    Hope you like the idea!

    I fail to see any point to it.

    If you can generate a random number, then you already have a random
    number. You can stop here and enjoy using your random number.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Claas@21:1/5 to Rich on Sat Mar 8 19:38:06 2025
    Rich wrote:
    Stefan Claas <fgrsna.pynnf@vagrearg.eh> wrote:
    Hi all,

    from the previous discussion with Richard I came up with a new idea to create a random number. I call the Go program lun = Lucky Number.

    How /random/ do you want this number to be?

    Here is a sample run with 3 seconds set. You can also use1 or many
    more seconds.

    $ lun 3

    Started: 2025-03-08 01:29:57

    2287128966796887 1741393797 2287130708190684
    2443764953918824 1741393798 2443766695312622
    8241182675020522 1741393799 8241184416414321

    Ended: 2025-03-08 01:29:59
    Time elapsed: 00:00:03
    Multiplying: 2287130708190684 * 8241184416414321
    Your lucky number is: 18848665950643714819328816385564
    SHA256: 28fd1445771c772f403eb4092b722640a529b5c84c3ee50bc6d631454e83daed

    The first column is a random number

    So, you already have a *random number*. Why do any more?

    , the second the local Unix-Epoch-Time

    Very *not* random.

    and the third shows the addition of column1 and column2.

    Provided the random number was "good enough randomness" this has no
    benefit.

    The lucky number was generated by multiplying the first and last
    value of the right column.

    The product R1 * R2 is little different, randomness wise, from the
    product R1 * (R2 + Predictable_Offset). If you can generate random
    numbers, what is the value in computing R1 * (R2 + Predictable_Offset)?

    Hope you like the idea!

    I fail to see any point to it.

    If you can generate a random number, then you already have a random
    number. You can stop here and enjoy using your random number.

    Why do you always have something to "complain" about? Enjoy the software,
    it is cool and not so boring like using /dev/urandom. Or better instead
    of "complaining" do something creative, crypto wise and show it to us too.

    Regards
    Stefan

    --
    Onion Courier Home Server Mon-Fri 15:00-21:00 UTC Sat-Sun 11:00-21:00 UTC ohpmsq5ypuw5nagt2jidfyq72jvgw3fdvq37txhnm5rfbhwuosftzuyd.onion:8080 inbox
    age1yubikey1qv5z678j0apqhd4ng7p22g4da8vxy3q5uvthg6su76yj0y8v7wp5kvhstum

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Claas@21:1/5 to Stefan Claas on Sat Mar 8 19:50:44 2025
    Stefan Claas wrote:
    Rich wrote:
    Stefan Claas <fgrsna.pynnf@vagrearg.eh> wrote:
    Hi all,

    from the previous discussion with Richard I came up with a new idea to create a random number. I call the Go program lun = Lucky Number.

    How /random/ do you want this number to be?

    Here is a sample run with 3 seconds set. You can also use1 or many
    more seconds.

    $ lun 3

    Started: 2025-03-08 01:29:57

    2287128966796887 1741393797 2287130708190684
    2443764953918824 1741393798 2443766695312622
    8241182675020522 1741393799 8241184416414321

    Ended: 2025-03-08 01:29:59
    Time elapsed: 00:00:03
    Multiplying: 2287130708190684 * 8241184416414321
    Your lucky number is: 18848665950643714819328816385564
    SHA256: 28fd1445771c772f403eb4092b722640a529b5c84c3ee50bc6d631454e83daed

    The first column is a random number

    So, you already have a *random number*. Why do any more?

    , the second the local Unix-Epoch-Time

    Very *not* random.

    and the third shows the addition of column1 and column2.

    Provided the random number was "good enough randomness" this has no benefit.

    The lucky number was generated by multiplying the first and last
    value of the right column.

    The product R1 * R2 is little different, randomness wise, from the
    product R1 * (R2 + Predictable_Offset). If you can generate random numbers, what is the value in computing R1 * (R2 + Predictable_Offset)?

    Hope you like the idea!

    I fail to see any point to it.

    If you can generate a random number, then you already have a random
    number. You can stop here and enjoy using your random number.

    Why do you always have something to "complain" about? Enjoy the software,
    it is cool and not so boring like using /dev/urandom. Or better instead
    of "complaining" do something creative, crypto wise and show it to us too.

    Not to mention that you can do lun with a pencil and paper to get good
    entropy (where humans fail) for a password, because it is simple and
    easy to understand.

    Regards
    Stefan


    --
    Onion Courier Home Server Mon-Fri 15:00-21:00 UTC Sat-Sun 11:00-21:00 UTC ohpmsq5ypuw5nagt2jidfyq72jvgw3fdvq37txhnm5rfbhwuosftzuyd.onion:8080 inbox
    age1yubikey1qv5z678j0apqhd4ng7p22g4da8vxy3q5uvthg6su76yj0y8v7wp5kvhstum

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Heathfield@21:1/5 to Rich on Sat Mar 8 18:54:31 2025
    On 08/03/2025 18:34, Rich wrote:
    Stefan Claas <fgrsna.pynnf@vagrearg.eh> wrote:
    Hi all,

    from the previous discussion with Richard I came up with a new idea to
    create a random number. I call the Go program lun = Lucky Number.

    How /random/ do you want this number to be?

    Here is a sample run with 3 seconds set. You can also use1 or many
    more seconds.

    $ lun 3

    Started: 2025-03-08 01:29:57

    2287128966796887 1741393797 2287130708190684
    2443764953918824 1741393798 2443766695312622
    8241182675020522 1741393799 8241184416414321

    Ended: 2025-03-08 01:29:59
    Time elapsed: 00:00:03
    Multiplying: 2287130708190684 * 8241184416414321
    Your lucky number is: 18848665950643714819328816385564
    SHA256: 28fd1445771c772f403eb4092b722640a529b5c84c3ee50bc6d631454e83daed

    The first column is a random number

    So, you already have a *random number*. Why do any more?

    , the second the local Unix-Epoch-Time

    Very *not* random.

    and the third shows the addition of column1 and column2.

    Provided the random number was "good enough randomness" this has no
    benefit.

    The lucky number was generated by multiplying the first and last
    value of the right column.

    The product R1 * R2 is little different, randomness wise, from the
    product R1 * (R2 + Predictable_Offset). If you can generate random
    numbers, what is the value in computing R1 * (R2 + Predictable_Offset)?

    Hope you like the idea!

    I fail to see any point to it.

    If you can generate a random number, then you already have a random
    number. You can stop here and enjoy using your random number.

    https://xkcd.com/221/

    --
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Heathfield@21:1/5 to Stefan Claas on Sat Mar 8 18:58:49 2025
    On 08/03/2025 18:38, Stefan Claas wrote:
    Rich wrote:

    <snip>


    I fail to see any point to it.

    If you can generate a random number, then you already have a random
    number. You can stop here and enjoy using your random number.

    Why do you always have something to "complain" about? Enjoy the software,
    it is cool and not so boring like using /dev/urandom.

    It's a NOP. What's so cool about a NOP?

    Or better instead
    of "complaining" do something creative, crypto wise and show it to us too.

    Turning a random number into a random number isn't creative.

    --
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Heathfield@21:1/5 to Stefan Claas on Sat Mar 8 19:00:32 2025
    On 08/03/2025 18:50, Stefan Claas wrote:

    <snip>

    Not to mention that you can do lun with a pencil and paper to get good entropy

    Or you can roll dice. I have 20d16 for that specific purpose.

    --
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Claas@21:1/5 to Richard Heathfield on Sat Mar 8 20:03:08 2025
    Richard Heathfield wrote:
    On 08/03/2025 18:50, Stefan Claas wrote:

    <snip>

    Not to mention that you can do lun with a pencil and paper to get good entropy

    Or you can roll dice. I have 20d16 for that specific purpose.

    Yes, good option.

    Regards
    Stefan

    --
    Onion Courier Home Server Mon-Fri 15:00-21:00 UTC Sat-Sun 11:00-21:00 UTC ohpmsq5ypuw5nagt2jidfyq72jvgw3fdvq37txhnm5rfbhwuosftzuyd.onion:8080 inbox
    age1yubikey1qv5z678j0apqhd4ng7p22g4da8vxy3q5uvthg6su76yj0y8v7wp5kvhstum

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Claas@21:1/5 to Richard Heathfield on Sat Mar 8 20:11:09 2025
    Richard Heathfield wrote:
    On 08/03/2025 18:38, Stefan Claas wrote:
    Rich wrote:

    <snip>


    I fail to see any point to it.

    If you can generate a random number, then you already have a random number. You can stop here and enjoy using your random number.

    Why do you always have something to "complain" about? Enjoy the software, it is cool and not so boring like using /dev/urandom.

    It's a NOP. What's so cool about a NOP?

    It demonstrates that even with a NOP you can do cool things.

    Or better instead
    of "complaining" do something creative, crypto wise and show it to us too.

    Turning a random number into a random number isn't creative.

    Well, Rich (and maybe you) should also show things to the community here,
    which can be discussed, otherwise this place is getting pretty boring.

    Regards
    Stefan

    --
    Onion Courier Home Server Mon-Fri 15:00-21:00 UTC Sat-Sun 11:00-21:00 UTC ohpmsq5ypuw5nagt2jidfyq72jvgw3fdvq37txhnm5rfbhwuosftzuyd.onion:8080 inbox
    age1yubikey1qv5z678j0apqhd4ng7p22g4da8vxy3q5uvthg6su76yj0y8v7wp5kvhstum

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to Stefan Claas on Sat Mar 8 21:32:12 2025
    Stefan Claas <fgrsna.pynnf@vagrearg.eh> wrote:
    Not to mention that you can do lun with a pencil and paper to get
    good entropy (where humans fail) for a password, because it is simple
    and easy to understand.

    How?

    There is zero explanation of lun here.

    Looking at the github of lun, there is also zero explanation (in fact,
    it is exactly what is shown here, one sample run with no explanation).

    The source might show how it is done, but that's the source code, an
    actual narriative explanation, with reasons for why various choices
    were made, is better than trying to retreive the method by reading the
    source.

    Looking at the source, how does someone with pencil and paper perform
    this magic?:

    n, _ := rand.Int(rand.Reader, max)

    As well, with just pencil and paper, obtaining a Unix epoch is quite an interesting 'by hand' calculation in order to perform this:

    epochTime := time.Now().Unix()

    I'll submit that once one has obtained a "rand.Int()" somehow, and
    computes a unix epoch time value somehow, that multipling and adding
    those large numbers is possible via pencil and paper (tedious, yes, but possible).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to Stefan Claas on Sat Mar 8 21:47:57 2025
    Stefan Claas <fgrsna.pynnf@vagrearg.eh> wrote:
    Why do you always have something to "complain" about?

    I am sorry you feel that way.

    Enjoy the software, it is cool

    Not really (in my opinion).

    and not so boring like using dev/urandom.

    Also, likely not as good a 'randomness' generator either.

    Or better instead of "complaining" do something creative, crypto wise
    and show it to us too.

    Ok, here's a simple random number generator using /dev/urandom:

    #!/usr/bin/tclsh

    set fd [open /dev/urandom {RDONLY BINARY}]
    binary scan [read $fd 16] ww hi lo
    close $fd

    puts "Your 128-bit random number is: [expr {abs($hi)*2^64 + abs($lo)}]"

    Four sample runs:

    ~$ ./random.tcl
    Your 128-bit random number is: 12845925169244013330
    ~$ ./random.tcl
    Your 128-bit random number is: 12267131317558982811
    ~$ ./random.tcl
    Your 128-bit random number is: 10434877321040400260
    ~$ ./random.tcl
    Your 128-bit random number is: 16618556391581443091

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Heathfield@21:1/5 to Rich on Sat Mar 8 21:42:44 2025
    On 08/03/2025 21:32, Rich wrote:

    <snip>

    Looking at the source, how does someone with pencil and paper perform
    this magic?:

    n, _ := rand.Int(rand.Reader, max)

    Roll some dice.

    d4 give you two bits at a time, d8 give you three, or d16 give
    you four. Quick and easy. Or if you prefer decimal, d10s are also
    readily available.

    As well, with just pencil and paper, obtaining a Unix epoch is quite an interesting 'by hand' calculation in order to perform this:

    epochTime := time.Now().Unix()

    You can skip that part by pretending it's 1970.

    --
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marcel Logen@21:1/5 to All on Sat Mar 8 23:34:33 2025
    Rich in sci.crypt:

    Ok, here's a simple random number generator using /dev/urandom:

    #!/usr/bin/tclsh

    set fd [open /dev/urandom {RDONLY BINARY}]
    binary scan [read $fd 16] ww hi lo
    close $fd

    puts "Your 128-bit random number is: [expr {abs($hi)*2^64 + abs($lo)}]"

    Interesting. But what is "ww"?

    16 * 8 = 128 -> OK, but ...:

    Four sample runs:

    ~$ ./random.tcl
    Your 128-bit random number is: 12845925169244013330
    ~$ ./random.tcl
    Your 128-bit random number is: 12267131317558982811
    ~$ ./random.tcl
    Your 128-bit random number is: 10434877321040400260
    ~$ ./random.tcl
    Your 128-bit random number is: 16618556391581443091
    ^^^
    64 (?)

    | $ echo 'l(16618556391581443091)/l(2)' | bc -l
    | 63.84942886744934185453

    But I'm not entirely sure if I'm on the right track.

    Marcel (Lines: 40)
    --
    ╭───╮ ╭──╮ ╭────╮ ╭─╮ ╭───╮ ..56..╭────╮
    ╮ ╰─╮ ╰────╮ ╭──╮ ╭──╯ │ │ ╭─╯ │ ╰─╯ ╰────╮ ╭───╮ ╰─╮ ╰─╮
    │ ╰────╮ │ │ ╰───╯ ╰─╯ ╰─╮ ╰───╮ ╭─────╯ │ ╰──╮ ╰─╮ ╰─╮
    ╰─────────╯ ╰──╯ ╰──────╯ ╰───────╯..55..╰────╯ ╰─

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Heathfield@21:1/5 to Stefan Claas on Sun Mar 9 00:19:52 2025
    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.

    --
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to Richard Heathfield on Sun Mar 9 04:02:27 2025
    Richard Heathfield <rjh@cpax.org.uk> wrote:
    On 08/03/2025 21:32, Rich wrote:

    <snip>

    Looking at the source, how does someone with pencil and paper perform
    this magic?:

    n, _ := rand.Int(rand.Reader, max)

    Roll some dice.

    d4 give you two bits at a time, d8 give you three, or d16 give
    you four. Quick and easy. Or if you prefer decimal, d10s are also
    readily available.

    True, that will work. Die for generating, pencil and paper for
    'recording' the result.

    However, if one had pencil, paper, and no die anywhere?

    As well, with just pencil and paper, obtaining a Unix epoch is quite
    an interesting 'by hand' calculation in order to perform this:

    epochTime := time.Now().Unix()

    You can skip that part by pretending it's 1970.

    Very true. Although then the offset random number is also identical to
    the non-offset number. Not that the offset is actually doing anything.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to Marcel Logen on Sun Mar 9 04:19:00 2025
    Marcel Logen <333200007110-0201@ybtra.de> wrote:
    Rich in sci.crypt:

    Ok, here's a simple random number generator using /dev/urandom:

    #!/usr/bin/tclsh

    set fd [open /dev/urandom {RDONLY BINARY}]
    binary scan [read $fd 16] ww hi lo
    close $fd

    puts "Your 128-bit random number is: [expr {abs($hi)*2^64 + abs($lo)}]"

    Interesting. But what is "ww"?

    Partially an attempt to make an unspoken point. For those of us who
    don't know go, reading go code can leave us /wondering/ what's going on
    (at least until we dig into the go docs enough to figure it out).

    The real explanation is it is the Tcl binary command operator for
    "convert 8 bytes into a signed 64-bit integer". In which case I
    suspect "w" was chosen to be short for (w)ide.

    The two w's in a row convert consequitive 8 bytes into unsigned
    64-bit integers, storing the first into variable "hi" and the second
    into variable lo.

    Then the [expr] call converts hi and lo into a single longer integer
    (which, thinking about it now, since I have to abs() them, means this
    is really outputting a 126 bit value instead.

    16 * 8 = 128 -> OK, but ...:

    Four sample runs:

    ~$ ./random.tcl
    Your 128-bit random number is: 12845925169244013330
    ~$ ./random.tcl
    Your 128-bit random number is: 12267131317558982811
    ~$ ./random.tcl
    Your 128-bit random number is: 10434877321040400260
    ~$ ./random.tcl
    Your 128-bit random number is: 16618556391581443091
    ^^^
    64 (?)

    | $ echo 'l(16618556391581443091)/l(2)' | bc -l
    | 63.84942886744934185453

    But I'm not entirely sure if I'm on the right track.

    Ugh..., no, you are right. ^ is xor. ** is power. The code should be:

    #!/usr/bin/tclsh

    set fd [open /dev/urandom {RDONLY BINARY}]
    binary scan [read $fd 16] ww hi lo
    close $fd

    puts "Your 126-bit random number is: [expr {abs($hi)*2**64 + abs($lo)}]"



    ~$ ./random.tcl
    Your 126-bit random number is: 169336852709816669373259866667412280949
    ~$ ./random.tcl
    Your 126-bit random number is: 32633310813732482344192030424429288689
    ~$ ./random.tcl
    Your 126-bit random number is: 76929973179533891725985594329257253768
    ~$ ./random.tcl
    Your 126-bit random number is: 49046152244045834428660372315683579977


    ~$ echo 'l(49046152244045834428660372315683579977)/l(2)' | bc -l
    125.20547946978097462900

    or

    ~$ echo 'l(169336852709816669373259866667412280949)/l(2)' | bc -l
    126.99316358625335794390

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Heathfield@21:1/5 to Rich on Sun Mar 9 05:39:50 2025
    On 09/03/2025 04:02, Rich wrote:
    Richard Heathfield <rjh@cpax.org.uk> wrote:
    On 08/03/2025 21:32, Rich wrote:

    <snip>

    Looking at the source, how does someone with pencil and paper perform
    this magic?:

    n, _ := rand.Int(rand.Reader, max)

    Roll some dice.

    d4 give you two bits at a time, d8 give you three, or d16 give
    you four. Quick and easy. Or if you prefer decimal, d10s are also
    readily available.

    True, that will work. Die for generating, pencil and paper for
    'recording' the result.

    However, if one had pencil, paper, and no die anywhere?

    4's always good. Very random, 4.

    --
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Claas@21:1/5 to Stefan Claas on Sun Mar 9 11:41:09 2025
    Stefan Claas wrote:

    $ echo ThankyouRichardfortheniceideathisisreallyfun | spiro -f out.txt Encoded matrix:

    niceideT
    entwE3ah
    huZg3Jta
    tfKvffhn
    ryQo9mik
    ol36p8sy
    flaersio
    drahciRu

    $ echo Thequickbrownfoxjumpsoverthelazydog | spiro | scos e 47 11
    .MGerqyy
    ?%TU.l07
    ]c(F:mkz
    )58h[I46
    +_.YXTy5
    5<\JB\Yo
    ^&8&GLed
    02+ADRMg

    :-)

    Regards
    Stefan

    --
    Onion Courier Home Server Mon-Fri 15:00-21:00 UTC Sat-Sun 11:00-21:00 UTC ohpmsq5ypuw5nagt2jidfyq72jvgw3fdvq37txhnm5rfbhwuosftzuyd.onion:8080 inbox
    age1yubikey1qv5z678j0apqhd4ng7p22g4da8vxy3q5uvthg6su76yj0y8v7wp5kvhstum

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Claas@21:1/5 to Richard Heathfield on Sun Mar 9 11:21:30 2025
    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! :-) I called my program 'spiro' since
    it gives a 'spiral' like output. To fill the matrix properly it
    uses padding.

    $ spiro -h
    Usage: spiro [OPTIONS] [TEXT]

    Options:
    -m SIZE Matrix size (must be power of 2, default: 8)
    -r DEG Rotation degree (90, 180, 270, default: 90)
    -f FILE Output/Input file name (optional for encoding)
    -d Decode mode (requires -f)

    Examples:
    spiro -m 8 -r 90 "Hello World"
    spiro -m 8 -r 90 -f encoded.txt "Hello World"
    spiro -m 8 -d -f encoded.txt
    echo "Long text" | spiro -m 16 -r 90

    $ echo ThankyouRichardfortheniceideathisisreallyfun | spiro -f out.txt
    Encoded matrix:

    niceideT
    entwE3ah
    huZg3Jta
    tfKvffhn
    ryQo9mik
    ol36p8sy
    flaersio
    drahciRu

    $ spiro -d -m 8 -f out.txt
    Decoded text: ThankyouRichardfortheniceideathisisreallyfuntwE3Jfm8p63QKZg3f9ov

    Regards
    Stefan

    --
    Onion Courier Home Server Mon-Fri 15:00-21:00 UTC Sat-Sun 11:00-21:00 UTC ohpmsq5ypuw5nagt2jidfyq72jvgw3fdvq37txhnm5rfbhwuosftzuyd.onion:8080 inbox
    age1yubikey1qv5z678j0apqhd4ng7p22g4da8vxy3q5uvthg6su76yj0y8v7wp5kvhstum

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Claas@21:1/5 to Stefan Claas on Sun Mar 9 12:44:28 2025
    Stefan Claas wrote:
    Stefan Claas wrote:

    $ echo ThankyouRichardfortheniceideathisisreallyfun | spiro -f out.txt Encoded matrix:

    niceideT
    entwE3ah
    huZg3Jta
    tfKvffhn
    ryQo9mik
    ol36p8sy
    flaersio
    drahciRu

    $ echo Thequickbrownfoxjumpsoverthelazydog | spiro | scos e 47 11
    .MGerqyy
    ?%TU.l07
    ]c(F:mkz
    )58h[I46
    +_.YXTy5
    5<\JB\Yo
    ^&8&GLed
    02+ADRMg

    Slightly improved:

    $ spiro -h
    Usage: spiro [OPTIONS] [TEXT]

    Options:
    -m SIZE Matrix size (must be power of 2, default: 8)
    -r DEG Rotation degree (90, 180, 270, default: 90)
    -f FILE Output/Input file name (optional)
    -d Decode mode

    Examples:
    spiro -m 8 -r 90 "HelloWorld"
    spiro -m 8 -r 90 -f encoded.txt "HelloWorld"
    spiro -d -m 8 -f encoded.txt
    echo "Longtext" | spiro -m 16 -r 90
    spiro -m 8 -r 90 | spiro -d -m 8

    $ echo Thisissofreakingcool | spiro -r 270 -m 32 +Pf+jbUVs4BlJNZWwOwHS0WBwOx1FZTE
    3mNbgd2cE3t+gR0iIftLDsfvMcIfdpCC
    Co3Xph6Jmg1zVjbzLoMXcpqK3BfIXisY
    3xBX7FHsaoL3WohPa6Zi0aJNkmQwa7BC
    FTBUn8IRX2ApKtk2kIoNI4uF2zE2jneL
    8bzqPSmze9pD8sqxiWANjN8bGaSpdKtZ
    4FdVh87p0=2sWvSgOWnkIeiFL2LrVYIk
    HnwT34Qaidd+JRQ6DZTAEYMky3Pzz+hv
    V8RF8PncwledT3J8eH+4PyzJTjKmYZkg
    puH0JuGAVVlBSUfUvCOEVMjGYCtiG5Kc
    E4lmYefbK97nT6FTq3XhmZbDUBTGu5MW
    dGNd2U4Ku+v1qcfo+3nENSC0Jk41rwbr
    l=IOa4f3fGzvXbzOo4pd1TCtwH9vbf3L
    oyFk=PbpFdOJBhx46YP5bqQ8QtLCN=Ky
    odPZfeJ3qfQcYm1rXX7te+RRAq0yrmie
    ckZB9RM8ExUjS+xGSvlUR8tOMbPaqFJv
    gqln9eKKEPlCyLKMYYrOVY0AHGXnmUzU
    n2n5S5y2uDoqIv7U7rjKq=xj=6ooivqT
    icnhQ4Uw3RTs37Z8nGd6lG=4N8UAaGfS
    k2Ck=vHOFScmdMGbd7zTfWs68WVDAhEp
    ayPZDn9hZkOJ=16IKOwb1NaobVDYq6Jz
    epOYyy+Mr3+Yr2LwGmU2DIwnN7lTPVQG
    rGt4yE2SepKaIpsDGLbv2exEeMRNBU7a
    frPq3dYmiPt2rQ+tj5xMcPJ9ebVOkR10
    obnPrGHf6HAiZb+npGZISvNcQRB4CXW2
    sBsI72hQ8YjYxSOG2daT=EJXT7ckJ9qO
    s7l25BetwAFXDMekcBLvBeuFDl42+7Bl
    i1fsUZd+y1XyDudO07CBQmLlZVSFDvYS
    sCuTEUt1E50wTKegJZXcbyt+psNLg0Zi
    i6jHxWWRcbX6HCmcqn85udgvrIiwAxH=
    hZqZwEyfUIkd=S+UtBMVKLjaBbEh9c1z
    TqFn3GfluCvGC0hniAEZwgofwm=bclBM

    Regards
    Stefan

    --
    Onion Courier Home Server Mon-Fri 15:00-21:00 UTC Sat-Sun 11:00-21:00 UTC ohpmsq5ypuw5nagt2jidfyq72jvgw3fdvq37txhnm5rfbhwuosftzuyd.onion:8080 inbox
    age1yubikey1qv5z678j0apqhd4ng7p22g4da8vxy3q5uvthg6su76yj0y8v7wp5kvhstum

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marcel Logen@21:1/5 to All on Sun Mar 9 13:45:39 2025
    Rich in sci.crypt:

    Marcel Logen <333200007110-0201@ybtra.de> wrote:

    [...]

    Interesting. But what is "ww"?

    Partially an attempt to make an unspoken point. For those of us who
    don't know go, reading go code can leave us /wondering/ what's going on
    (at least until we dig into the go docs enough to figure it out).

    The real explanation is it is the Tcl binary command operator for
    [...]

    Thanks for this.

    | $ echo 'l(16618556391581443091)/l(2)' | bc -l
    | 63.84942886744934185453

    But I'm not entirely sure if I'm on the right track.

    Ugh..., no, you are right. ^ is xor. ** is power. The code should be:

    Ah, OK. I didn't come up with XOR. :-)

    Marcel
    --
    Sun Mar 9 13:45:40 2025 CET (1741524340)
    pc-731
    87 h642 fkba
    Lines: 32

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Claas@21:1/5 to Stefan Claas on Sun Mar 9 13:50:06 2025
    Stefan Claas wrote:
    Stefan Claas wrote:
    Stefan Claas wrote:

    $ echo ThankyouRichardfortheniceideathisisreallyfun | spiro -f out.txt Encoded matrix:

    niceideT
    entwE3ah
    huZg3Jta
    tfKvffhn
    ryQo9mik
    ol36p8sy
    flaersio
    drahciRu

    $ echo Thequickbrownfoxjumpsoverthelazydog | spiro | scos e 47 11
    .MGerqyy
    ?%TU.l07
    ]c(F:mkz
    )58h[I46
    +_.YXTy5
    5<\JB\Yo
    ^&8&GLed
    02+ADRMg

    Slightly improved:

    https://github.com/706f6c6c7578/spiro

    Regards
    Stefan

    --
    Onion Courier Home Server Mon-Fri 15:00-21:00 UTC Sat-Sun 11:00-21:00 UTC ohpmsq5ypuw5nagt2jidfyq72jvgw3fdvq37txhnm5rfbhwuosftzuyd.onion:8080 inbox
    age1yubikey1qv5z678j0apqhd4ng7p22g4da8vxy3q5uvthg6su76yj0y8v7wp5kvhstum

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to Rich on Tue Mar 11 18:20:24 2025
    Rich <rich@example.invalid> writes:

    Richard Heathfield <rjh@cpax.org.uk> wrote:
    On 08/03/2025 21:32, Rich wrote:

    <snip>

    Looking at the source, how does someone with pencil and paper perform
    this magic?:

    n, _ := rand.Int(rand.Reader, max)

    Roll some dice.

    d4 give you two bits at a time, d8 give you three, or d16 give
    you four. Quick and easy. Or if you prefer decimal, d10s are also
    readily available.

    True, that will work. Die for generating, pencil and paper for
    'recording' the result.

    However, if one had pencil, paper, and no die anywhere?

    How may sides does the pencil have? ;-)

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to Ben Bacarisse on Tue Mar 11 19:11:44 2025
    Ben Bacarisse <ben@bsb.me.uk> wrote:
    Rich <rich@example.invalid> writes:

    Richard Heathfield <rjh@cpax.org.uk> wrote:
    On 08/03/2025 21:32, Rich wrote:

    <snip>

    Looking at the source, how does someone with pencil and paper perform
    this magic?:

    n, _ := rand.Int(rand.Reader, max)

    Roll some dice.

    d4 give you two bits at a time, d8 give you three, or d16 give
    you four. Quick and easy. Or if you prefer decimal, d10s are also
    readily available.

    True, that will work. Die for generating, pencil and paper for
    'recording' the result.

    However, if one had pencil, paper, and no die anywhere?

    How may sides does the pencil have? ;-)

    A round pencil, with no sides. :)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to Richard Heathfield on Tue Mar 11 19:59:55 2025
    Richard Heathfield <rjh@cpax.org.uk> wrote:
    On 11/03/2025 19:11, Rich wrote:
    Ben Bacarisse <ben@bsb.me.uk> wrote:
    Rich <rich@example.invalid> writes:

    Richard Heathfield <rjh@cpax.org.uk> wrote:
    On 08/03/2025 21:32, Rich wrote:

    <snip>

    Looking at the source, how does someone with pencil and paper perform >>>>>> this magic?:

    n, _ := rand.Int(rand.Reader, max)

    Roll some dice.

    d4 give you two bits at a time, d8 give you three, or d16 give
    you four. Quick and easy. Or if you prefer decimal, d10s are also
    readily available.

    True, that will work. Die for generating, pencil and paper for
    'recording' the result.

    However, if one had pencil, paper, and no die anywhere?

    How may sides does the pencil have? ;-)

    A round pencil, with no sides. :)

    You've got paper, though.

    https://www.professororigami.com/how-to-make-an-origami-cube/

    :-)

    I admit defeat. :) With this one can create a 'die' from paper. It
    may be biased (in that one side may very well weigh slightly more than
    another) but barring massive bias it should be random enough.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Heathfield@21:1/5 to Rich on Tue Mar 11 19:52:22 2025
    On 11/03/2025 19:11, Rich wrote:
    Ben Bacarisse <ben@bsb.me.uk> wrote:
    Rich <rich@example.invalid> writes:

    Richard Heathfield <rjh@cpax.org.uk> wrote:
    On 08/03/2025 21:32, Rich wrote:

    <snip>

    Looking at the source, how does someone with pencil and paper perform >>>>> this magic?:

    n, _ := rand.Int(rand.Reader, max)

    Roll some dice.

    d4 give you two bits at a time, d8 give you three, or d16 give
    you four. Quick and easy. Or if you prefer decimal, d10s are also
    readily available.

    True, that will work. Die for generating, pencil and paper for
    'recording' the result.

    However, if one had pencil, paper, and no die anywhere?

    How may sides does the pencil have? ;-)

    A round pencil, with no sides. :)

    You've got paper, though.

    https://www.professororigami.com/how-to-make-an-origami-cube/

    :-)

    --
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Harnden@21:1/5 to Rich on Tue Mar 11 20:44:28 2025
    On 11/03/2025 19:59, Rich wrote:
    Richard Heathfield <rjh@cpax.org.uk> wrote:
    On 11/03/2025 19:11, Rich wrote:
    Ben Bacarisse <ben@bsb.me.uk> wrote:
    Rich <rich@example.invalid> writes:

    Richard Heathfield <rjh@cpax.org.uk> wrote:
    On 08/03/2025 21:32, Rich wrote:

    <snip>

    Looking at the source, how does someone with pencil and paper perform >>>>>>> this magic?:

    n, _ := rand.Int(rand.Reader, max)

    Roll some dice.

    d4 give you two bits at a time, d8 give you three, or d16 give
    you four. Quick and easy. Or if you prefer decimal, d10s are also
    readily available.

    True, that will work. Die for generating, pencil and paper for
    'recording' the result.

    However, if one had pencil, paper, and no die anywhere?

    How may sides does the pencil have? ;-)

    A round pencil, with no sides. :)

    You've got paper, though.

    https://www.professororigami.com/how-to-make-an-origami-cube/

    :-)

    I admit defeat. :) With this one can create a 'die' from paper. It
    may be biased (in that one side may very well weigh slightly more than another) but barring massive bias it should be random enough.

    Way too complicated: Chew the paper until its one homongonised mess,
    spilt it out, mould into a cube.

    Extra credit if you can manage a d20.

    I wonder why nobody wants /my/ random numbers!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Heathfield@21:1/5 to Stefan Claas on Wed Mar 12 12:32:51 2025
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Heathfield@21:1/5 to Marcel Logen on Sat Mar 15 20:04:38 2025
    On 15/03/2025 19:44, Marcel Logen wrote:
    Richard Heathfield in sci.crypt:

    <snip>

    for(i = 0; i < n; i++)
    {
    for(j = 7; j >= 0; j--)
    {
    fprintf(stdout, "%d", !!(b[i] & (1 << j)));
    ^^
    What does this do? Is it necessary?
    (As you see, I'm not a C programmer. ;-)

    Okay. In C, ! is the `not' operator.

    0 is false, 1 is true, non-zero is true, but not true is false. So:

    x = 6;
    printf("%d", x); prints 6.
    printf("%d", !x); prints 0 because not non-zero is false.
    printf("%d", !!x); prints 1 because not not non-zero is true.

    So !!x maps 0 to 0 and everything else to 1. If you're printing
    bits, it's just the job.



    }
    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);

    "dump(l, 8);" (?)

    Oh. Er... yeah, good spot. Oops. Fortunately, it amounts to the
    same thing in this case.


    return 0;
    }
    [...]
    #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

    Can you explain this a little bit?

    Three extraordinarily useful macros.

    x is a pointer to an array of unsigned char.

    i is a bit index, so to speak.

    Say i is 77, which is

    01001101

    i >> 3 gives us 00001001, or 9.
    i & 7 gives us 00000101, or 5.

    So these macros respectively query, set, or clear bit 5 of byte 9
    (counting from x).

    A somewhat hurried explanation, so feel free to ask further.

    --
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marcel Logen@21:1/5 to All on Sat Mar 15 20:44:04 2025
    Richard Heathfield in sci.crypt:

    [...]

    Tell you what, I'll let my source code do the talking and give
    you a demo run at the end:

    Thank you. Interesting.

    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)));
    ^^
    What does this do? Is it necessary?
    (As you see, I'm not a C programmer. ;-)

    }
    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);

    "dump(l, 8);" (?)

    return 0;
    }
    [...]
    #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

    Can you explain this a little bit?

    Marcel
    --
    Sat Mar 15 20:44:04 2025 CET (1742067844)
    pc-731
    87 sene jdap
    Lines: 67

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marcel Logen@21:1/5 to All on Sun Mar 16 12:15:16 2025
    Richard Heathfield in sci.crypt:

    On 15/03/2025 19:44, Marcel Logen wrote:

    [...]

    Okay. In C, ! is the `not' operator.

    I was aware of that. So I thought that the double exclamation
    mark was superfluous.

    0 is false, 1 is true, non-zero is true, but not true is false. So:
    ^^^^^^^^^^^^^^^^
    This is probably the crucial point.

    x = 6;
    printf("%d", x); prints 6.
    printf("%d", !x); prints 0 because not non-zero is false.
    printf("%d", !!x); prints 1 because not not non-zero is true.

    So !!x maps 0 to 0 and everything else to 1. If you're printing
    bits, it's just the job.

    A good trick! So a kind of normalization, AFAICS.

    [...]

    #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
    [...]
    Say i is 77, which is

    01001101

    i >> 3 gives us 00001001, or 9.
    i & 7 gives us 00000101, or 5.

    So these macros respectively query, set, or clear bit 5 of byte 9
    (counting from x).

    A somewhat hurried explanation, so feel free to ask further.

    I'll take a closer look at this. For now, your explanation is
    good enough for me. Thanks.

    Marcel
    --
    Sun Mar 16 12:15:16 2025 CET (1742123716)
    pc-731
    87 msdl b59m
    Lines: 52

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Heathfield@21:1/5 to Marcel Logen on Sun Mar 16 11:53:49 2025
    On 16/03/2025 11:15, Marcel Logen wrote:
    Richard Heathfield in sci.crypt:

    On 15/03/2025 19:44, Marcel Logen wrote:

    [...]

    Okay. In C, ! is the `not' operator.

    I was aware of that. So I thought that the double exclamation
    mark was superfluous.

    0 is false, 1 is true, non-zero is true, but not true is false. So:
    ^^^^^^^^^^^^^^^^
    This is probably the crucial point.

    It is.

    x = 6;
    printf("%d", x); prints 6.
    printf("%d", !x); prints 0 because not non-zero is false.
    printf("%d", !!x); prints 1 because not not non-zero is true.

    So !!x maps 0 to 0 and everything else to 1. If you're printing
    bits, it's just the job.

    A good trick! So a kind of normalization, AFAICS.

    Precisely, yes.

    [...]

    #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
    [...]
    Say i is 77, which is

    01001101

    i >> 3 gives us 00001001, or 9.
    i & 7 gives us 00000101, or 5.

    So these macros respectively query, set, or clear bit 5 of byte 9
    (counting from x).

    A somewhat hurried explanation, so feel free to ask further.

    I'll take a closer look at this. For now, your explanation is
    good enough for me. Thanks.

    I knocked up a quick sieve for you so that you can see the macros
    being used in another context - here, to tick off compounds (by
    which I mean non-primes) a la Eratosthenes. (I also fixed a tiny
    and probably harmless bug in BIT_QRY, where x was insufficiently parenthiprotected.)

    #include <stdio.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

    #define MAX 1000

    int main(void)
    {
    unsigned char sieve[(MAX+7)/8] = {0};

    int base = 2;
    int candidate = 0;
    int count = 0;

    BIT_SET(sieve, 0); /* 0 is not prime */
    BIT_SET(sieve, 1); /* 1 is not prime */

    while(base <= MAX)
    {
    for(candidate = 2 * base; candidate <= MAX; candidate += base)
    {
    BIT_SET(sieve, candidate);
    }
    ++base;
    }

    for(candidate = 0; candidate <= MAX; candidate++)
    {
    if(!BIT_QRY(sieve, candidate))
    {
    ++count;
    printf(" %4d", candidate);
    if(count % 10 == 0)
    {
    putchar('\n');
    }
    }
    }
    putchar('\n');
    printf("%d primes in the range 0-%d.\n", count, MAX);

    return 0;
    }


    --
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marcel Logen@21:1/5 to All on Sun Mar 16 15:57:20 2025
    Richard Heathfield in sci.crypt:

    [...]

    I knocked up a quick sieve for you so that you can see the macros
    being used in another context - here, to tick off compounds (by
    which I mean non-primes) a la Eratosthenes.

    It works. :-)

    (I also fixed a tiny
    and probably harmless bug in BIT_QRY, where x was insufficiently >parenthiprotected.)

    #include <stdio.h>

    #define BIT_QRY(x,i) (((x)[(i)>>3] & (1<<((i)&7)))!=0)

    This is actually another C question:

    Why does it have to be "(x)" and "(i)" everywhere instead of
    "x" and "i"? What kind of "protection" is meant here?

    Marcel
    --
    Sun Mar 16 15:57:20 2025 CET (1742137040)
    pc-731
    87 v7s9 11d2
    Lines: 29

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Heathfield@21:1/5 to Marcel Logen on Sun Mar 16 15:55:10 2025
    On 16/03/2025 14:57, Marcel Logen wrote:
    Richard Heathfield in sci.crypt:

    <snip>

    #define BIT_QRY(x,i) (((x)[(i)>>3] & (1<<((i)&7)))!=0)

    This is actually another C question:

    Why does it have to be "(x)" and "(i)" everywhere instead of
    "x" and "i"? What kind of "protection" is meant here?


    Turn to Number 3 in your songsheets if you will, to this rather
    simpler macro:

    #define BAD_DOUBLE(x) 2*x

    and this invocation:

    int e = 1;
    int f = 29;
    int g = BAD_DOUBLE(e+f);

    We'd hope for a result of 60, but what we get is 31 because
    BAD_DOUBLE(e+f) expands to 2*e+f which is 2*1+29, and precedence
    requires the * to happen before the +.

    Parentheses solve the problem:

    #define GOOD_DOUBLE(y) 2*(y)
    int h = GOOD_DOUBLE(e+f);

    which expands to 2*(e+f) and gives us the 60 we were after.

    They are not, however, a complete solution:

    #define DODGY_DOUBLE(x) (x)+(x)

    looks solid enough, but DODGY_DOUBLE(e++)

    will expand to (e++)+(e++)

    which modifies a value twice between sequence points, and the
    resultant behaviour is undefined by the rules of the language.

    If in doubt, steer well clear of side effects in macros.

    --
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marcel Logen@21:1/5 to All on Sun Mar 16 23:21:50 2025
    Richard Heathfield in sci.crypt:

    On 16/03/2025 14:57, Marcel Logen wrote:
    Richard Heathfield in sci.crypt:

    #define BIT_QRY(x,i) (((x)[(i)>>3] & (1<<((i)&7)))!=0)

    This is actually another C question:

    Why does it have to be "(x)" and "(i)" everywhere instead of
    "x" and "i"? What kind of "protection" is meant here?
    [...]
    If in doubt, steer well clear of side effects in macros.

    Ah, OK, all this refers to macros.

    I had initially assumed that it was generally about paren-
    theses around variable names.

    Marcel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Heathfield@21:1/5 to Marcel Logen on Mon Mar 17 07:03:09 2025
    On 16/03/2025 22:21, Marcel Logen wrote:
    Richard Heathfield in sci.crypt:

    On 16/03/2025 14:57, Marcel Logen wrote:
    Richard Heathfield in sci.crypt:

    #define BIT_QRY(x,i) (((x)[(i)>>3] & (1<<((i)&7)))!=0)

    This is actually another C question:

    Why does it have to be "(x)" and "(i)" everywhere instead of
    "x" and "i"? What kind of "protection" is meant here?
    [...]
    If in doubt, steer well clear of side effects in macros.

    Ah, OK, all this refers to macros.

    I had initially assumed that it was generally about paren-
    theses around variable names.

    No, I think that'th Lithp.

    --
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marcel Logen@21:1/5 to All on Mon Mar 17 19:17:51 2025
    Richard Heathfield in sci.crypt:

    On 16/03/2025 22:21, Marcel Logen wrote:

    [C]
    Ah, OK, all this refers to macros.

    I had initially assumed that it was generally about paren-
    theses around variable names.

    No, I think that'th Lithp.

    :-)

    Marcel
    --
    Mon Mar 17 19:17:51 2025 CET (1742235471)
    pc-731
    87 1puv 34lj
    Lines: 20

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)