Permalink
Browse files

example hash collision attack

  • Loading branch information...
coolaj86 committed Mar 8, 2012
1 parent 2c4af6c commit e278ef60c75ed5f77e7db1f3655802c269b610d0
Showing with 39 additions and 0 deletions.
  1. +39 −0 pedantic/hash-collision-attack.js
@@ -0,0 +1,39 @@
+(function () {
+ "use strict";
+
+ var size
+ , startTime
+ , endTime
+ , array
+ , key
+ , maxKey
+ ;
+
+ size = Math.pow(2, 22); // 16 is just an example, could also be 15 or 17
+
+ startTime = Date.now();
+
+ array = [];
+ key = 0;
+ maxKey = (size - 1) * size;
+ for (; key <= maxKey; key += size) {
+ array[key] = 0;
+ }
+
+ endTime = Date.now();
+
+ console.log('Inserting ', size, ' evil elements took ', endTime - startTime, ' ms', "\n");
+
+ startTime = Date.now();
+
+ array = [];
+ key = 0;
+ maxKey = size - 1;
+ for (; key <= maxKey; ++key) {
+ array[key] = 0;
+ }
+
+ endTime = Date.now();
+
+ console.log('Inserting ', size, ' good elements took ', endTime - startTime, ' ms', "\n");
+}());

0 comments on commit e278ef6

Please sign in to comment.