Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8" />
- <title>German Tax Generator</title>
- <meta name="author" content="JavaScript: Jonas Pfeil">
- <meta name="author" content="Original: Martin Wolters">
- <script>
- var MIXFACT=256;
- //Code from http://www.naden.de/blog/zufallszahlen-in-javascript-mit-mathrandom
- function rrand(min, max) {
- if(min > max) {
- return -1;
- }
- if(min == max) {
- return min;
- }
- var r;
- do {
- r = Math.random();
- }
- while(r == 1.0);
- return min + parseInt(r * (max-min+1));
- }
- function checksum(id) {
- var out;
- var i, sum = 0, prod = 10;
- for(i = 0; i < 10; i++) {
- sum = (id[i] + prod) % 10;
- if(sum == 0)
- sum = 10;
- prod = (sum * 2) % 11;
- }
- out = 11 - prod;
- if(out == 10)
- out = 0;
- return out;
- }
- function mix(id) {
- var i, pos1, pos2;
- var buf;
- for(i = 0; i < MIXFACT; i++) {
- pos1 = rrand(0,9);
- do {
- pos2 = rrand(0,9);
- } while(pos1 == pos2);
- buf = id[pos1];
- id[pos1] = id[pos2];
- id[pos2] = buf;
- }
- pos1 = rrand(0,9);
- do {
- pos2 = rrand(0,9);
- } while(pos1 == pos2);
- id[pos1] = id[pos2];
- }
- function generateTaxId(){
- var id=[0,1,2,3,4,5,6,7,8,9];
- mix(id);
- var ret="";
- for(var i=0;i<10;++i)
- ret+=id[i];
- ret+=checksum(id);
- return ret;
- }
- </script>
- <style>
- #license
- {
- display:none;
- width:12cm;
- text-align:justify;
- }
- </style>
- </head>
- <body>
- <input type="text"><input type="button" onclick="this.previousSibling.value=generateTaxId()" value="Generate Tax ID"><br>
- <input type="button" onclick="this.nextSibling.style.display='block'" value="License"><div id="license">
- <p>Copyright (C) 2012 Martin Wolters, Jonas Pfeil</p>
- <p>This program is free software; you can redistribute it and/or
- modify it under the terms of the <a href="http://www.gnu.org/licenses/gpl-2.0.txt">GNU General Public License</a>
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.</p>
- <p>This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.</p>
- <p>You should have received a copy of the GNU General Public License
- along with this program; if not, write to <br>
- the Free Software Foundation, Inc.<br>
- 51 Franklin Street, Fifth Floor<br>
- Boston, MA 02110-1301, USA</p>
- </div>
- </body>
- </html>
Add Comment
Please, Sign In to add comment