progs/ap4.js
changeset 166 bba0504abcf0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/progs/ap4.js	Tue Sep 23 02:04:34 2014 +0100
@@ -0,0 +1,20 @@
+var salt = 'secret key' 
+
+function mk_hash(s) {
+    return crypto.createHash('sha1').update(s).digest('hex')
+}
+
+function mk_cookie(c) {
+    return c.toString() + '-' + mk_hash(c.toString() + salt)
+}
+
+function gt_cookie(s) {
+    var splits = s.split("-", 2);
+    var counter = parseInt(splits[0])
+    var hash = splits[1]
+    if (mk_hash(counter.toString() + salt) == hash) {
+        return counter
+    } else { return 0 }
+}
+
+app.get('/', function(req, res){ .... });