{"id":181,"date":"2009-02-08T00:00:00","date_gmt":"2009-02-08T07:00:00","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=714"},"modified":"2009-02-08T00:00:00","modified_gmt":"2009-02-08T07:00:00","slug":"crackable-string-encoding","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=181","title":{"rendered":"Crackable String Encoding"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar encode:Object = new Object();\r\nvar decode:Object = new Object();\r\nvar a:Array = &quot; abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890&quot;.split(&quot;&quot;);\r\n\r\n\/\/ change this for different encoded results\r\nvar offset:int = 10;\r\n\r\nfor (var i:int = 0; i&lt;a.length; i++){\r\n\tvar index:int = (a.length - i - offset) % a.length;\r\n\tencode&#x5B;a&#x5B;i]] = a&#x5B;index];\r\n\tdecode&#x5B;a&#x5B;index]] = a&#x5B;i];\r\n}\r\n\r\nfunction encodeString(str:String):String{\r\n\treturn map(str, encode);\r\n}\r\n\r\nfunction decodeString(str:String):String{\r\n\treturn map(str, decode);\r\n}\r\n\r\nfunction map(str:String, smode:Object):String{\r\n\tvar n:String = &quot;&quot;;\r\n\tfor (var i:int = 0; i&lt;str.length; i++){\r\n\t\tvar char:String = str.charAt(i);\r\n\t\tvar en:String = smode&#x5B;char];\r\n\t\tif (en){\r\n\t\t    n += en;\r\n\t\t}else{\r\n\t\t\tn += char;\r\n\t\t}\r\n\t}\r\n\treturn n;\r\n}\r\n\r\n\/\/ test out the functions\r\n\r\nvar input:String = &quot;This is a regular string&quot;;\r\n\r\ntrace(input);\r\n\r\nvar encoded:String = encodeString(input);\r\n\r\ntrace(&quot;encoded: &quot;, encoded);\r\n\r\ntrace(&quot;decoded: &quot;,decodeString(encoded));\r\n\r\n\/*\r\noutputs:\r\n\r\nThis is a regular string\r\nencoded:  gSRH1RH1Z1IVTFOZI1HGIRMT\r\ndecoded:  This is a regular string\r\n\r\n*\/\r\n<\/pre>\n<p>The above demos an intentionally simple string encoding technique.<\/p>\n<p>This is a technique I use if I need to encode strings but don&#8217;t care if someone figures out what the string value actually is. For me, this is more common than needing hard\/impossible to crack string encoding algorithms. A good example is an e-card&#8230; a url for an ecard could look like this:<\/p>\n<p>www.birthdaycardthing.com\/?name=joe&#038;age=32<\/p>\n<p>or it could look like this:<\/p>\n<p>www.birthdaycardthing.com\/?i=brx&#038;x=5p<\/p>\n<p>I wrapped this snippet up into a class and made a few minor tweaks. The class is called SimpleCipher it has two static methods and one static property&#8230;  <\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nimport com.actionsnippet.utils.SimpleCipher;\r\n\/\/ same as offset above, but can be set at any time\r\n\/\/ new encode and decode Objects will be calculated\r\nSimpleCipher.offset = 1;\r\nvar input:String = &quot;SimpleCipher encoding and decoding&quot;;\r\n\t\t\t \r\ntrace(&quot;input: &quot;, input);\r\n\t\t\t \r\nvar encoded:String = SimpleCipher.encode(input);\r\n\t\t\t \r\ntrace(&quot;encoded: &quot;, encoded);\r\ntrace(&quot;decoded: &quot;, SimpleCipher.decode(encoded));\r\n\/*\r\noutputs:\r\ninput:  SimpleCipher encoding and decoding\r\nencoded:  RhlokdBhogdq0dmbnchmf0 mc0cdbnchmf\r\ndecoded:  SimpleCipher encoding and decoding\r\n*\/\r\n<\/pre>\n<p><a href=\"http:\/\/www.actionsnippet.com\/source\/SimpleCipher.zip\">Download SimpleCipher Class<\/a><br \/>\n(this class uses a static initializer&#8230; see yesterdays post)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>var encode:Object = new Object(); var decode:Object = new Object(); var a:Array = &quot; abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890&quot;.split(&quot;&quot;); \/\/ change this for different encoded results var offset:int = 10; for (var i:int = 0; i&lt;a.length; i++){ var index:int = (a.length &#8211; i &#8211; offset) % a.length; encode&#x5B;a&#x5B;i]] = a&#x5B;index]; decode&#x5B;a&#x5B;index]] = a&#x5B;i]; } function encodeString(str:String):String{ return map(str, encode); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,21],"tags":[3,4],"class_list":["post-181","post","type-post","status-publish","format-standard","hentry","category-oop","category-strings","tag-actionscript","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=181"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/181\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}