FAQ  •  Register  •  Login
UKLockpickers.co.uk Lockpicking supplies such as Lockpicks, tools, and more! COMMANDOLOCK.COM Military grade padlock systems lockpickshop.com A source for lockpicking supplies such as lockpicks, locksmith tools, and more!

Random Bitting Generator (with constraints)

<<

piotr

User avatar

Contributor
Contributor

Posts: 738

Joined: Thu Nov 25, 2010 3:59 am

Location: Victoria, Australia

Post Wed Jan 02, 2013 1:08 am

Random Bitting Generator (with constraints)

Implemented in JavaScript because of its ubiquity (not because I think it's a great language).
As per the comment in the header, you can run this on a Windows/Win32 system via the Windows Script Host (which I believe is installed on Windows XP and later systems as standard). Cut the code out and paste it into a text file called combinate.js
Open a window with the command prompt (usually C:\>) and cd to the directory in which you saved combinate.js
At the command-line enter the following:

cscript combinate.js

The prgram should spit out 12 5-digit codes with certain arbitrary constraints (that may or may not suit your need). The major parameters have been implemented as pseudo-constants (JavaScript doesn't support real symbolic constants AFAIK) to make the program easier to alter. If you don't feel confident adapting this code then just post your requirement and myself or another member will help.

  Code:
// combinate.js
// At Windows command-line enter:
// C:\> cscript combinate.js
//

var NUM_DIGITS = 5
var INTERVAL_START = 1
var INTERVAL_END = 6
var BATCH_SIZE = 12
var REGEX_1 = /^6/
var REGEX_2 = /61/
var REGEX_3 = /16/

function randomWithinInterval(from, to)
{
    return Math.floor(Math.random() * (to - from + 1) + from)
}
var previousCut = ""
var currentCut = ""
var code = ""
var batchCount = 0
   
while( batchCount < BATCH_SIZE )
{
    for(i = 1; i <= NUM_DIGITS; i++)
    {
        currentCut = randomWithinInterval(INTERVAL_START, INTERVAL_END)
        // Filter out identical contiguous digits and increment/decrement pattern
        while ( previousCut == currentCut ||
              (previousCut + 1) == currentCut ||
              (previousCut - 1) == currentCut )
        {
            currentCut = randomWithinInterval(INTERVAL_START, INTERVAL_END)
        }
        previousCut = currentCut
        code += currentCut
    }

    // Filter out unwanted codes (MACS violations)
    if ( code.search(REGEX_1) < 0 &&
         code.search(REGEX_2) < 0 &&
         code.search(REGEX_3) < 0 )
    {
        batchCount++
        WScript.Echo(code)
    }
    code = ""
}   
Last edited by piotr on Wed Jan 02, 2013 5:05 am, edited 1 time in total.
<<

piotr

User avatar

Contributor
Contributor

Posts: 738

Joined: Thu Nov 25, 2010 3:59 am

Location: Victoria, Australia

Post Wed Jan 02, 2013 5:06 am

Re: Random Bitting Generator (with constraints)

Caveman wrote:
piotr wrote:The prgram should spit out 12 6-digit codes


Guessing you mean 5-digit from the look of the code :)


Yep. I stand corrected.
<<

abroxis

Contributor
Contributor

Posts: 349

Joined: Sun Apr 27, 2008 10:12 am

Post Thu Jan 03, 2013 8:09 am

Re: Random Bitting Generator (with constraints)

I tried the js and got an error message

E:\combinate.js(51, 6) Microsoft JScript compilation error: Expected ';'

I am clueless about this stuff , could some one please suggest what I may have done wrong?

As far as I know I copied the js script verbatim from the listing given.
<<

piotr

User avatar

Contributor
Contributor

Posts: 738

Joined: Thu Nov 25, 2010 3:59 am

Location: Victoria, Australia

Post Thu Jan 03, 2013 8:20 am

Re: Random Bitting Generator (with constraints)

I've tested it on Windows XP and I run it with just:

C:\> cscript combinate.js

Can you try to specify cscript (i.e. the console version of the Windows Script Host) as above?

I have version 5.7 of WSH

C:\notes>cscript /?
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.
<<

s1deshowmick

User avatar

Contributor
Contributor

Posts: 634

Joined: Fri Aug 08, 2008 5:31 am

Location: Western Australia

Post Thu Jan 03, 2013 8:41 am

Re: Random Bitting Generator (with constraints)

Ah, all i understood was the bit about "The programme should spit out 12 - 5 digit codes"

I'll stick to picking Lockwood's.
If you can't be good, Be good at it.

http://au.youtube.com/S1DESHOWMICK

Return to HAL 3000 - Computer Geeks

Who is online

Users browsing this forum: No registered users

Don't forget to visit our sponsors for all of your lockpicking needs!
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Grop
"CA Black" theme designed by stsoftware