Webstatt.org - Community seit 2006 - 2012 (2024?)

Verschiebechiffre

user-343
21.09.2006 19:35

Verschiebechiffre v.0.1
Folgende Funktionen verstellen den ASCII-Wert eines Zeichens um den Modulus aus 256 von der Prüfsumme vom Passwort.
<?php
/*

Verschiebechiffre.
Chiffriert einen String mit einem Passwort, mit selbigen (Naja, nicht ganz...) lässt sich wieder entschlüsseln.
Funktioniert nur mit ASCII!

Copyright (C) 2006 Basilius Sauter

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

*/

function shiftcipher_encode($sEncode, $sPass) {
$iPass = (crc32($sPass)%256);
$iEncodeLenght = StrLen($sEncode);
$sCrypt = '';

for($i = 0; $i < $iEncodeLenght; $i++) {
$iAsciiVal = ord($sEncode{$i});
$iAsciiVal += $iPass;
while($iAsciiVal > 255) {
$iAsciiVal -= 256;
}

$sCript .= chr($iAsciiVal);
}

return $sCript;
}

function shiftcipher_decode($sDecode, $sPass) {
$iPass = (crc32($sPass)%256);
$iDecodeLenght = StrLen($sDecode);
$sDecript = '';

for($i = 0; $i < $iDecodeLenght; $i++) {
$iAsciiVal = ord($sDecode{$i});
$iAsciiVal -= $iPass;
while($iAsciiVal > 255) {
$iAsciiVal -= 256;
}

$sDecript .= chr($iAsciiVal);
}

return $sDecript;
}


$var = shiftcipher_encode('Hello World', 'bla'zwinkern;
$var2 = shiftcipher_decode($var, 'bla'zwinkern;

var_dump($var, $var2);

?>



Ausgabe:
string(11) "ž¥¥¨Y¨«¥"
string(11) "Hello World"