Ok, i found this online as a way to make certain strings interact with certain web pages, but can anyone help me break it down a little? function Populate() { hex = new MakeArray(); hex[1] = "0"; hex[2] = "1"; hex[3] = "2"; hex[4] = "3"; hex[5] = "4"; hex[6] = "5"; hex[7] = "6"; hex[8] = "7"; hex[9] = "8"; hex[10] = "9"; hex[11] = "a"; hex[12] = "b"; hex[13] = "c"; hex[14] = "d"; hex[15] = "e"; hex[16] = "f"; } function get_hex(N) { s = ""; A = N; while (A >= 16) { B = A % 16; A = Math.floor(A / 16); s = s + hex[B+1]; } s += hex[A+1]; return transpose(s); } function transpose(s) { N = s.length; t = ""; for (i = 0; i < N; i++) { t = t + s.substring(N-i-1, N-i); } // zero-pad s = t; for (i = 0; i < (5 - t.length); i++) { s = "0" + s; } return s; } Code (markup):
My math is a bit rusty but that looks like a terrible way to convert a base 10 number into a base 16 number. He's basically converting a number into its hex code but it's done really poorly.
Yes, so here's whats going on: Populate creates an array of these numbers. Get_hex uses these numbers to do some conversion and return a transposed hex code. Finally, transpose does some stuff to that hex code and spits out a variable "s". Maybe changing hex codes? Stackoverflow.com has a lot of programmers that are willing to help too.
Here's someone trying to figure out the exact same code from 5 years ago: http://www.programmers-corner.com/forums/post-15436.html
It starts with a decimal number (N) and an empty result (s). It uses the modulus operator (%) to get the remainder of the number divided by 16. It then looks up the hex value of the remainder and adds it to the result in sequence. The number is then divided by 16 and the loop starts again. Once the number is under 16, the loop stops and the final hex code is added. The string is then transposed (reversed) and leading zeros added if it's too short. Try this with a really large number, like 10000. <html> <head> <script type="text/javascript"> hex = new Array(); hex[1] = "0"; hex[2] = "1"; hex[3] = "2"; hex[4] = "3"; hex[5] = "4"; hex[6] = "5"; hex[7] = "6"; hex[8] = "7"; hex[9] = "8"; hex[10] = "9"; hex[11] = "a"; hex[12] = "b"; hex[13] = "c"; hex[14] = "d"; hex[15] = "e"; hex[16] = "f"; function get_hex(N) { s = ""; // start with an empty answer string A = N; // create a copy of the number while (A >= 16) { // keep looping while the number is greater or equal to 16 B = A % 16; // get the remainder of the number divided by 16 A = Math.floor(A / 16); // divide the number by 16 and save as the new number s = s + hex[B+1]; // add the hex code for the remainder to the string addAnswer(s); // write answer to the page } s += hex[A+1]; // now that the number is less than 16, add it's hex code to the string. addAnswer(s); // write answer to the page return transpose(s); // return the reversed string with leading zeros added } function transpose(s) { N = s.length; t = ""; for (i = 0; i < N; i++) { // move from end to the start copying characters to a new string t = t + s.substring(N-i-1, N-i); } s = t; for (i = 0; i < (5 - t.length); i++) { // add zeros to the front if string less than five s = "0" + s; } return s; } function convert() { var dec = document.getElementById('number').value; var hex = get_hex(dec); addAnswer(hex); } function addAnswer(n) { var answer = document.getElementById('answer').innerHTML; document.getElementById('answer').innerHTML = answer + '<br />' + n; } </script> <style type='text/css'> input, p { display: block; margin: 10px 0; } </style> </head> <body> <input id='number' type='text' /> <input type='button' onclick='convert()' value='Convert' /> <div id='answer'></div> </body> </html> Code (markup):
anyone think they could write a little piece of javascript that could effectively reverse it? I know the last 3 numbers are not coded because that is the password of the user when inputted. I may be able to swing a few dollars your say if you can, but no guarantees. If you can you can use the number 112602 as N as i know that is a valid number for the entry.
HellBomb, Why do you think that a programmer would do this for free? If you need programming help, hire them or at least offer something in kind - not say "but no guarantees". I don't expect YOU to bomb hell for free!