Skip to content

Instantly share code, notes, and snippets.

@mwgamera
mwgamera / ver36.c
Created July 8, 2011 22:55
Implementation of Verhoeff scheme adapted to aplhanumeric data
/* Group operation in D18 (precomputed) */
static int d18_op[36][36] = {
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35},
{ 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17, 0,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,18},
{ 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17, 0, 1,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,18,19},
{ 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17, 0, 1, 2,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,18,19,20},
{ 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17, 0, 1, 2, 3,22,23,24,25,26,27,28,29,30,31,32,33,34,35,18,19,20,21},
{ 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17, 0, 1, 2, 3, 4,23,24,25,26,27,28,29,30,31,32,33,34,35,18,19,20,21,22},
{ 6, 7, 8, 9,10,11,12,13,14,15,16,17, 0, 1, 2, 3, 4, 5,24,25,26,27,28,29,30,31,32,33,34,35,18,19,20,21,22,23},
{ 7, 8, 9,10,11,12,13,14,15,16,17, 0, 1, 2, 3, 4, 5, 6,25,26,27,28,29,30,31,32,33,34,35,18,19,20,21,22,23,24},
@mwgamera
mwgamera / Ver36.java
Created July 17, 2011 01:56
Alphanumeric derivative of Verhoeff check digit scheme in Java
/**
* Alphanumeric check digit based on Verhoeff scheme.
* A check digit algorithm for alphanumeric data that detects
* all single digit errors, all adjacent transpositions, and
* over 98% of jump transpositions, twin errors and jump twins.
* @author mwgamera
**/
public class Ver36 {
/** Order of dihedral group used. */
@mwgamera
mwgamera / ver36.js
Created July 18, 2011 06:09
Alphanumeric derivative of Verhoeff check digit in javascript.
var Ver36 = function() {
"use strict";
var N = 18, N2 = N*2;
var d18_op; // D18 group operation table
var d18_inv; // D18 group inverse
var perm; // the permutation decomposed into cycles
var a2i,i2a; // ASCII translation tables
var NA=0xff; // invalid digit marker in ASCII table
// initialization code
@mwgamera
mwgamera / vtnearpal.pl
Created February 13, 2012 04:30
Script to help choosing a palette for colorized ascii-art or ansi-art for modern terminals
#!/usr/bin/env perl
# vtnearpal.pl [+256 | +88] [-selector] colors [...]
# Find the optimal elements of terminal palette to represent given set
# of colors. Assumes either 256- or 88-color mode and allows limiting
# the set of terminal colors to given selection (perl slice indices).
use strict;
use Graphics::ColorObject 'RGB_to_Lab';
use Algorithm::Munkres 'assign';
# (id,rgb) -> [id, r, g, b, L, a, b]
/* gcc -O3 -ansi -Wall -Wextra -pedantic -static termwait.c -lrt -o termwait */
#define _POSIX_C_SOURCE 200809L
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/wait.h>
/* gcc -O3 -ansi -Wall -Wextra -pedantic -static shwait.c -lrt -lutil -o shwait */
#define _XOPEN_SOURCE 700
#include <errno.h>
#include <fcntl.h>
#include <pty.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <sys/mman.h>
#include <termios.h>
@mwgamera
mwgamera / ver36.lua
Created August 7, 2012 18:22
Verhoeff36 in Lua
#!/usr/bin/lua
do
local N = 18
-- Group operation in D18
local d18_op = {}
for i = 1, N do
d18_op[i] = {}
for j = 1, N do
@mwgamera
mwgamera / README
Created August 29, 2012 22:54
klg.passwordEntropy
klg.passwordEntropy
===================
1. Motivation
Provision of password strength checker integrated into user interface can
easily guide users in choosing stronger passwords. It can not substitute
strict password policy but it should make passwords harder to crack on
average without frustrating users (like strict policies do).
@mwgamera
mwgamera / passwordEntropy.min.js
Created August 29, 2012 23:00
klg.passwordEntropy
(function(m){"use strict";function n(g,c){var d=0;c.d.i(g.length);g.unshift(255);for(var a=2;a<=g.length;a++){var f=g.slice(0,a);f.length>c.length&&(f=f.slice(f.length-c.length,f.length));d+=i(f,c)}setTimeout(function(){c.d.e()},0);return d}function i(g,c){for(var d,a=0;1<g.length;){if((d=c.get(g))!==c.ZERO)return a+d[0];a+=c.get(g.slice(0,g.length-1))[1];g=g.slice(1)}(d=c.get(g))!==c.ZERO?(a+=Math.log((c.a+2)/(c.b+1))/Math.log(2),a+=d[0],c.b++):(a+=Math.log((c.a+2)/(c.a-c.b+1))/Math.log(2),a+=c.j);c.a++;return a}
function o(){var g={},c=2048,d=0;this.i=function(a){c=a>c?a:c};this.set=function(a,f){return(g[a]=[d++,f])[1]};this.get=function(a){if(void 0!==g[a])return g[a][0]=d++,g[a][1]};this.e=function(){var a=[],f=0,b;for(b in g)g.hasOwnProperty(b)&&(a[f++]=[g[b][0],b]);if(a.length>c&&(a.sort(function(b,f){return b[0]-f[0]}),a.length>c))for(f=1;f<c-a.length;f++)delete g[a[f][1]]}}var p=function(){function g(f){var b=[],a=[],e=0,c=0,g=RegExp("[!#%,:;=@_]","g"),j=g.exec(f);if(!j||j.index)b.push([0,0],a=[0,
0,
@mwgamera
mwgamera / Obfuscator.php
Created September 12, 2012 02:19
Ultimate obfuscator for e-mail addresses
<?php
/**
* Obfuscate UTF-8 strings in a way that allows easy decoding in Javascript
* while cryptographically forcing potentially misbehaving harvester to make
* additional request.
**/
class Obfuscator {
const SEED_LENGTH = 16;
const KEY_ROUNDS = 20;