Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Wombat's Bit Scrambler

by wombat (Curate)
on Mar 10, 2001 at 00:24 UTC ( #63343=sourcecode: print w/replies, xml ) Need Help??
Category: Cryptography
Author/Contact Info Wombat
Description: I recognize that this is not a security group, but I figure there must be at least a few cypherpunks in the lot of you. I came up with this scheme for encrypting text, and submit it to you to see if anyone can come up with any obvious holes.

The way this works, is a user types a passphrase which gets turned into a number between 0 and the maximum size of an integer (4,294,967,924). This number then is used to seed the random number generator. The program then collects single numbers between 0 and 7 by repeatedly calling rand(), until it has a bit vector. Then for each character of input, it maps the characters bits to the bit vector producing a scrambled character which it prints to STDOUT. By entering the same passphrase again, you get the same srand seed and thus can decrypt your bits at a later date.

Features include:
Arbitrarily long passphrases: Type as much as you like, the seed won't mind.
Non-portability: (It's not a bug!) I realize that everyone has different random number generators. That's okay. I'm mostly using this to lock down my own personal secret files. I don't think the security would be compromised too much if a person sent the particulars of their random number generator along with cyphercode if they wanted a friend to get a message.
No way to decrypt the text: I haven't coded the decryptor yet, so as of now, once encrypted, things STAY encrypted! :-)

So yeah! Like, peer-review me and stuff! BTW: I do realize that this is "Weak security" at best, and probably can be defeated by brute force if so desired. I know. But BESIDES that... :-)

#!/usr/bin/perl -w
$key=0;        #Initialize variables. 
print "Enter passphrase: ";
chomp $phrase;
@letters = split //,$phrase;
foreach $CHAR (@letters) {  #Use phrase to create random seed
  $modulo = $newbits % 10;
  if ($updown == 0) {
    if ($key < 0){$key*=-1;}
    if ($key>4294967294){$updown=1;}
  if ($updown == 1) {
    if ($key<0){$updown=0;}
srand $key;
while(<STDIN>) {
 @inputchars = split //;
 foreach $CHAR (@inputchars){
 for (0..8) {      #Translate the input char into binary
  $t = $charnum % (2**$_);
  if($t==$oldt) {
  }else {$binarr[8-$_]=1;}
  while ($i<8) {   #Assemble the key bit vector.
    if ($arrdone[$randout]==0) {
  for(0..7) {      #Assemble the scrambled bit vector.
    if ($binarr[$_]==1) {
    $outchar[$shifter[$_]] = 1;
    else {$outchar[$shifter[$_]] =0;}
  for(0..7) {     #Rejoin the new bits to an ord
    if ($outchar[$_]==1) {
  $och= chr($sum);    #Print the char.
  print $och;
  $i=0;     #Reset variables

Replies are listed 'Best First'.
Re: Wombat's Bit Scrambler
by arhuman (Vicar) on Mar 10, 2001 at 02:46 UTC
    I'm one of those who always look for new improved things.

    So I was rather interested by your post.

    Anyway I'd like to point out some weakness/problem which could be interesting to enhance/solve :

    1) The key space (the seed is the key) is really too small in my humble opinion (32 bits !!!!).
    why not use your passphrase to create several seed which could be used to introduce more entropy.
    (produce N seeds and use N pseudo random generator?)

    2) I think that you supposition that each pseudo random generator is different is risky.
    very few good generators exists and in fact it seems that a bad one is the most used (linear congruential generator)
    In fact it's probable that different system will produce the same values with the same seed.
    And even if I don't know if the Perl rand function will give the same values on different system given the same seed,
    It's higly possible that if someone implement this algo in another language the rand function will be a linear congruential generator.

    3) BTW if the rand function is a Linear congruential generator the period may be ridiculously short (16838 for ANSI one) so long text encrypting would lead to easy cryptanalisis.
    Moreover whatever the period of your generator you shouldn't use it to encrypt an unlimited plain text (or a very long message).

    4) you're algo seems weak against choosen (or even known) text attack

    But as I said before , I like your try and hope you'll go on trying to enhance this.

    As long as you remember that whatever your skill without a long review by (real) cryptanalists, it IS weak security.

    UPDATE : A good reading could be the article "Randomness - The Perl Journal, Winter 1996"

    "Trying to be a SMART lamer" (thanx to Merlyn ;-)
      There is a module on CPAN called Crypt::Random, which is supposed
      to provide numbers that are random enough for cryptological applications.
      This module might be worth looking at.

      In the end, there can be only one!
        If Crypt::Random is really random (and it seems to be) then you won't be able to decrypt the ciphered message giving the same seed.

        "Trying to be a SMART lamer" (thanx to Merlyn ;-)
      First of all, laugh at me, hehehe. I'm almost computer illiterate when it comes to hacking and programing. Me and a friend are really interested in simbolism and cryptology, so I was wondering if you could help me out with this incryption program, how do I run it(in lamens terms please), install it, make it work, etc etc... Any and all help will be very well recieved and you will have my utmost gratitude. Thank you. -The illeterate computer guru KC P.S. haha ^ I know, Oxymoron:P
        The program in question is a perl script, which means you will have to install perl before you can use it. Here is where you can find information about doing so.

        For the curious, this appears to be a question asking for help with Wombat's Bit Scrambler, perhaps stumbled across by a google search.

        Simbology* just noticed that..
Re: Wombat's Bit Scrambler
by bladx (Chaplain) on Mar 10, 2001 at 21:28 UTC
    Overall, wombat, I think you had a great idea for your program, and though I haven't studied the entirety of the program, I was thinking about that thing that arhuman was commenting on... and that was "If Crypt::Random is really random (and it seems to be) then you won't be able to decrypt the ciphered message giving the same seed." And that's something important to think about... make sure to not have it randomize to the point of not being able to reconvert the information after being scrambled!! Although you probably have already considered this, hope my opinion helps a bit!! Later.

    bladx ~ ímuchas veces tengo preguntas!
      They are called pseudo random number generators for a reason. They are not really random, just close to it.
Re (tilly) 1: Wombat's Bit Scrambler
by tilly (Archbishop) on Mar 10, 2001 at 02:32 UTC
    What is wrong with MD5?

    Nevermind, I misread the problem. But again I would suggest using standard encryption techniques unless you care to know a lot more about the subject than I do.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://63343]
[erix]: nice cover with the spitting image of George (and a great solo by Prince at the end )
[Discipulus]: good night monks! i feel fresh as the turkey in the hoven but i need to sleep
[planetscape]: gobble, gobble, Discipulus!
[erix]: Discipulus: buonanotte! :)
[stonecolddevin]: man we need a new guitar legend
[stonecolddevin]: Clapton has issues playing nowadays
[stonecolddevin]: Prince is gone
[stonecolddevin]: Van Halen is still around but I haven't heard any of their new stuff
[erix]: oh, 41M views -- everyone has seen it already then :)
[erix]: Alvin Lee dead too -- we're stuck with Karl, I'm afraid :)

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2017-06-22 21:18 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (531 votes). Check out past polls.