implementing client-based vernam coding into add form
authorDaniel Hromada <hromi@Aphrodité.(none)>
Mon, 1 Nov 2010 16:52:20 +0000 (23:52 +0700)
committerDaniel Hromada <hromi@Aphrodité.(none)>
Mon, 1 Nov 2010 16:52:20 +0000 (23:52 +0700)
data/templates/own_templates/1548927.tpl
data/templates/own_templates/1549864.tpl
wwwroot/js/rc4.js [new file with mode: 0644]

index 215658de08a816e4c8195d6993a5e39960509b5c..e1a3da032e89b5a89995bc3b25674b35fd10118e 100644 (file)
@@ -26,8 +26,8 @@
   </select>
   -->
 
-  <input type='text' name='template_id' size=5 value='4' title='[submission: 4 | forum: 3 | nodeshell: 2 | article: 5 | data: 12]' />
-
+  <input type='text' name='template_id' size=5 value='4' id='vernamseed' title='[submission: 4 | forum: 3 | nodeshell: 2 | article: 5 | data: 12]' />
+  <input type='submit' name='template_event' value='encrypt' onClick='document.getElementById("node_content").innerHTML=rc4Encrypt(document.getElementById("vernamseed").value,document.getElementById("node_content").innerHTML);'/>
   <input type='submit' name='template_event' value='preview' />
 
   <select name='sel_help' onchange='document.getElementById("node_content").innerHTML += sel_help.value;'  style='margin-right:4px'>
index 2c9af21f075b57ad34c059536b7837859916d9dd..5d0ba361f768a94d488be2e77d5a50ec688cf987 100644 (file)
@@ -9,6 +9,8 @@
 
 <title>{* title.tpl *}{include file="791948.tpl"}</title>
 
+
+<script language="JavaScript" type="text/javascript" src="/js/jrc4.js"></script>
 <script language="JavaScript" type="text/javascript">
 <!--
 {literal}
diff --git a/wwwroot/js/rc4.js b/wwwroot/js/rc4.js
new file mode 100644 (file)
index 0000000..a2c8a75
--- /dev/null
@@ -0,0 +1,55 @@
+/* RC4 symmetric cipher encryption/decryption
+ * Copyright (c) 2006 by Ali Farhadi.
+ * released under the terms of the Gnu Public License.
+ * see the GPL for details.
+ *
+ * Email: ali[at]farhadi[dot]ir
+ * Website: http://farhadi.ir/
+ */
+
+/**
+ * Encrypt given plain text using the key with RC4 algorithm.
+ * All parameters and return value are in binary format.
+ *
+ * @param string key - secret key for encryption
+ * @param string pt - plain text to be encrypted
+ * @return string
+ */
+function rc4Encrypt(key, pt) {
+       s = new Array();
+       for (var i=0; i<256; i++) {
+               s[i] = i;
+       }
+       var j = 0;
+       var x;
+       for (i=0; i<256; i++) {
+               j = (j + s[i] + key.charCodeAt(i % key.length)) % 256;
+               x = s[i];
+               s[i] = s[j];
+               s[j] = x;
+       }
+       i = 0;
+       j = 0;
+       var ct = '';
+       for (var y=0; y<pt.length; y++) {
+               i = (i + 1) % 256;
+               j = (j + s[i]) % 256;
+               x = s[i];
+               s[i] = s[j];
+               s[j] = x;
+               ct += String.fromCharCode(pt.charCodeAt(y) ^ s[(s[i] + s[j]) % 256]);
+       }
+       return ct;
+}
+
+/**
+ * Decrypt given cipher text using the key with RC4 algorithm.
+ * All parameters and return value are in binary format.
+ *
+ * @param string key - secret key for decryption
+ * @param string ct - cipher text to be decrypted
+ * @return string
+*/
+function rc4Decrypt(key, ct) {
+       return rc4Encrypt(key, ct);
+}
\ No newline at end of file
This page took 0.136173 seconds and 4 git commands to generate.