Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Encryption/hashing algorithm.

by jmcnamara (Monsignor)
on Sep 12, 2001 at 18:37 UTC ( [id://111916]=perlquestion: print w/replies, xml ) Need Help??

jmcnamara has asked for the wisdom of the Perl Monks concerning the following question:


The code below is a Perl version of an encryption/hashing algorithm used by OpenOffice to generate pseudo passwords for Excel worksheets. The input is a single 16 bit integer.

Does anyone recognise the algorithm or methodology used.

Apologies for being off-topic.
sub Decode { my $nPasswd = shift || 0; my $sPasswd = ''; my $sDummy = ''; my $nLen = 9; my $nDummy = 0; my $nNewChar = 0; $nPasswd ^= 0xCE4B; $nDummy = $nPasswd; while ( !($nDummy & 0x8000) && $nLen ) { $nLen--; $nDummy <<= 1; } if ( !$nLen ) { $nLen = 2; } if ( ($nLen ^ $nPasswd) & 0x0001 ) { $nLen++; } if ( $nLen == 9 ) { $nLen = 10; $nPasswd ^= 0x8001; } $nPasswd ^= $nLen; if ( $nLen < 9 ) { $nPasswd <<= (8 - $nLen); } for ( my $iChar = $nLen; $iChar > 0; $iChar-- ) { if ($iChar == 10) { $nNewChar = ($nPasswd & 0xC000) | 0x0400; $nPasswd ^= $nNewChar; $nNewChar >>= 2; } elsif ($iChar == 9) { $nNewChar = 0x4200; $nPasswd ^= $nNewChar; $nNewChar >>= 1; } elsif ($iChar == 1) { $nNewChar = $nPasswd & 0xFF00; } else { $nNewChar = ($nPasswd & 0xE000) ^ 0x2000; if ( !$nNewChar ) { $nNewChar = ($nPasswd & 0xF000) ^ 0x1800; } if ( $nNewChar == 0x6000 ) { $nNewChar = 0x6100; } $nPasswd ^= $nNewChar; $nPasswd <<= 1; } $nNewChar >>= 8; $nNewChar &= 0x00FF; $sPasswd .= chr $nNewChar; } print "<$sPasswd>\n\n"; }


John.
--

Replies are listed 'Best First'.
Re: Encryption/hashing algorithm.
by ncw (Friar) on Sep 12, 2001 at 23:46 UTC
    This looks to me like a CRC algorithm.

    If it is (and I haven't analysed it extensively) it is not very well implemented.

    Crypto-wise the algorithm is linear and hence trivially insecure. It may be a reasonable hashing algorithm for a certain class of problem, but it certainly isn't a good encryption algorithm.

    Here is a guide to CRCs "everything you ever wanted to know but were afraid to ask..."

    http://www.dementia.org/~strong/public/faqs/crc.faq.txt

    And here is my favourite reference for crypto design

    Applied Cryptography

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://111916]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-20 04:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found