2015.02.25 13:52

Simple encrypt/decrypt(AS3, PHP)

액션스크립트 -------------------------------------------------

package { import com.hurlant.util.Base64; public class Simplecrypt { static public function encrypt(str:String, key:String = '%key&'):String { var result:String = ''; for (var i:int = 0; i < str.length; i++) { var char:String = str.substr(i, 1); var keychar:String = key.substr((i % key.length) - 1, 1); var ordChar:int = char.charCodeAt(0); var ordKeychar:int = keychar.charCodeAt(0); var sum:int = ordChar + ordKeychar; char = String.fromCharCode(sum); result = result + char; } return Base64.encode(result); } static public function decrypt(str:String, key:String = '%key&'):String { var result:String = ''; var str:String = Base64.decode(str); for (var i:int = 0; i < str.length; i++) { var char:String = str.substr(i, 1); var keychar:String = key.substr((i % key.length) - 1, 1); var ordChar:int = char.charCodeAt(0); var ordKeychar:int = keychar.charCodeAt(0); var sum:int = ordChar - ordKeychar; char = String.fromCharCode(sum); result = result + char; } return result; } } }


PHP -------------------------------------------------

<?php class Simplecrypt { public static function encrypt($string, $key='%key&') { $result = ''; for($i=0; $i<strlen($string); $i++) { $char = substr($string, $i, 1); $keychar = substr($key, ($i % strlen($key))-1, 1); $ordChar = ord($char); $ordKeychar = ord($keychar); $sum = $ordChar + $ordKeychar; $char = chr($sum); $result.=$char; } return base64_encode($result); } public static function decrypt($string, $key='%key&') { $result = ''; $string = base64_decode($string); for($i=0; $i<strlen($string); $i++) { $char = substr($string, $i, 1); $keychar = substr($key, ($i % strlen($key))-1, 1); $ordChar = ord($char); $ordKeychar = ord($keychar); $sum = $ordChar - $ordKeychar; $char = chr($sum); $result.=$char; } return $result; } }

출처 : https://cambiatablog.wordpress.com/2010/08/24/simple-encryptdecrypt-in-as3-and-php-base64-blues/

Trackback 0 Comment 0