#include <stdio.h>
#include <stdlib.h>
/*
The pin encoding monster. Encrypts and generates
lists of numeric pin codes using simple over- and
underflow arithmetic. Security based on 1 master
PIN code.
Use:
– enter your sheet of codes to be protected, into pins array
– check the 3 variables that control what kind of PINs are accepted
– enter your main PIN code
– run program to produce output sheet of encrypted PINs
The over- and underflow means that each PIN, containing
arabian numeric characters (0..9), is added a key number.
The key number is overflowing (if over 9, goes from 0 and round again)
and underflowing (if decreasing 0, then roll over to 9 and count down).
This means the lineage is infinite. You can use
Freely distributable, keep the copyright and e-mail
markings intact. Enjoy. No guarantees as usual.
DO NOT use for counterfeiting, hacking, or any other purpose
which might bring you harm. Do as ye wish, less harm none.
http://en.wikipedia.org/wiki/The_Golden_Rule
http://en.wikipedia.org/wiki/Code_of_Hammurabi
Feedback appreciated:
Jukka Paulin, CS Student
<jukka.paulin@gmail.com>
November 2001, Finland
===================================================================
= I wish a *peaceful Christmas* to all the people in the world. =
= Stop the war. Revenge begets revenge! Recursion quite obvious. =
= Over and out. =
===================================================================
*/
#define PIN_COUNT 74
#define MAX_PIN_LEN 4
#define MAX_KEY_LEN 4
char * pins[PIN_COUNT] = {
“2360”,”1233″,”4765″,
“4031”,”4612″,”8710″,”4438″,
“4725”,”5982″,”6809″,”3630″,
“3759”,”5787″,”3816″,”3432″,
“1303”,”2135″,”6839″,”7655″,
“2152”,”7983″,”3361″,”8054″,
“1174”,”6336″,”6623″,”3476″,
“9019”,”8591″,”5530″,”6945″,
“8136”,”8746″,”9349″,”1822″,
“4943”,”5139″,”3426″,”2432″,
“8997”,”5394″,”3970″,”3729″,
“3601”,”1719″,”8795″,”6661″,
“5352”,”6669″,”4760″,”8397″,
“8820”,”9917″,”4304″,”6864″,
“7251”,”2243″,”5186″,”1860″,
“2800”,”9131″,”1615″,”2261″,
“8605”,”3423″,”6845″,”2396″,
“4503”,”5819″,”6613″,”9001″,
“3389”,”5078″};
char * confirmCodes [18] = {
“9441”,”0508″,”3006″,
“0781”,”6199″,”1017″,
“0439”,”5023″,”7545″,
“6055”,”2334″,”6388″,
“6184”,”6367″,”5412″,
“5551”,”7623″,”2642″};
/*
Params: – *pin is the PIN number in asciiZ
– *key is the KEY in asciiZ
– *targetBuffer is where the encoded PIN gets written
*/
void encode (char *pin, const char *key, char *targetBuffer) {
int length;
int j;
char tmp;
length=strlen(pin);
if (length<1) return;
if (length>MAX_KEY_LEN) {
printf (“\nerror: KEY too long. Maximum is: %d\n”,MAX_KEY_LEN);
return;
}
for (j=0; j<length; j++) {
tmp = *pin++;
tmp += *key++ – ‘0’;
if (tmp > ‘9’) tmp -= 10;
*targetBuffer++ = tmp;
}
}
/*
Makes a Nordea SOLO -type PIN list. This has 80 disposable
PINs and a fixed list of 18 verification codes. The verification
codes are not overwritten on use, they last until the whole list
expires.
– parameters: listOfPins = a pointer to PIN codes in ASCII
listOfCodes = a pointer to fixed codes in ASCII
codesLetters = a table of alphabets which match fixed codes
(might be eg. “ABCDEFGHJ” where ‘I’ is skipped because it
would morph easily with ‘1’. If the list length is less
than the amount of PINs, they used over again.)
startOrdinal = the ordinal number of first PIN, even if
the PIN actually omitted
excludedAmount = how many codes have been omitted from start
rowsInColumn = how many numbers to print in one vertical column
key = the encoding key */
int makeNordeaList (char *listOfPins[], char *listOfCodes[],
const char *codesLetters,
int startOrdinal, int excludedAmount,
int totalAmount, int rowsInColumn, const char *key)
{
char encoded[5];
int remainder;
int columns;
encoded[4] = 0; /* set string terminator */
/* Some fiddling first with the format of the output list.
– format the list so that it reminds the original one even
though some codes may have been omitted from the start
*/
if (rowsInColumn == 0) {
printf (“\nError: rowsInColumn = 0. Not a valid format!\n”);
return;
}
remainder = excludedAmount % rowsInColumn;
columns = totalAmount / rowsInColumn;
if ((excludedAmount > 0) && ((excludedAmount % rowsInColumn) != 0))
{
printf (“\nList needs modification on format.\n”);
} else {
/* List fine, needs no adjustment. */
}
}
int main ()
{
/* Params: pins, codes, chars, start, excluded, total, percolumn, key */
makeNordeaList (pins,confirmCodes,”ABCDEFGHJKLMNPRSTU”,
01, 7, 80, 10, “7890”);
return 0;
}
Leave a Reply