Merge pull request #73 from AlexDvorak/master

added DecimalToHex
This commit is contained in:
Mohit Sharma
2019-03-21 12:06:59 +05:30
committed by GitHub
2 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,24 @@
function intToHex(num){
switch(num){
case 10: return "A";
case 11: return "B";
case 12: return "C";
case 13: return "D";
case 14: return "E";
case 15: return "F";
}
return num;
}
function decimalToHex(num){
let hex_out = [];
while(num > 15) {
hex_out.push(intToHex(num%16));
num = Math.floor(num / 16);
}
return intToHex(num) + hex_out.join("");
}
// test cases
console.log(decimalToHex(999098) === "F3EBA");
console.log(decimalToHex(123) === "7B");

View File

@ -140,6 +140,13 @@ In cryptography, a **transposition cipher** is a method of encryption by which t
Mathematically a bijective function is used on the characters' positions to encrypt and an inverse function to decrypt.
###### Source: [Wikipedia](https://en.wikipedia.org/wiki/Transposition_cipher)
----------------------------------------------------------------------------------------------------------------------
## Checksums
### Luhn's
The Luhn algorithm or Luhn formula, also known as the "modulus 10" or "mod 10" algorithm, is a simple checksum formula used to validate a variety of identification numbers, such as credit card numbers, IMEI numbers, National Provider Identifier numbers in the United States, Canadian Social Insurance Numbers, Israel ID Numbers and Greek Social Security Numbers. It was created by IBM scientist Hans Peter Luhn and described in U.S. Patent No. 2,950,048, filed on January 6, 1954, and granted on August 23, 1960.
###### Source: [Wikipedia](https://en.wikipedia.org/wiki/Transposition_cipher)
[bubble-toptal]: https://www.toptal.com/developers/sorting-algorithms/bubble-sort
[bubble-wiki]: https://en.wikipedia.org/wiki/Bubble_sort
[bubble-image]: https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Bubblesort-edited-color.svg/220px-Bubblesort-edited-color.svg.png "Bubble Sort"