-
-
Save dolmen/1800884 to your computer and use it in GitHub Desktop.
Checksum RIO (portabilité de numéro de téléphone en France)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copiez sur coffeescript.org, onglet "Try CoffeeScript" pour l'exécuter en ligne. | |
exports = {} | |
# | |
# Used to calculate the checksum | |
# http://fr.wikipedia.org/wiki/Relev%C3%A9_d'identit%C3%A9_op%C3%A9rateur | |
# | |
exports.calcChksm = (oo, q, rrrrrr, notel) -> | |
concatenation = "#{oo}#{q}#{rrrrrr}#{notel}" | |
ordre = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+" | |
a = b = c = 0 | |
for i in concatenation | |
p = ordre.indexOf i | |
a = (1 * a + p ) % 37 | |
b = (2 * b + p ) % 37 | |
c = (4 * c + p ) % 37 | |
ccc = "#{ordre[a]}#{ordre[b]}#{ordre[c]}" | |
return ccc | |
# | |
# Used to check if a RIO, match the phone number | |
# | |
exports.checkRIO = (rio, notel) -> | |
throw Error("RIO is mandatory !") if rio == null | |
throw Error("Invalid RIO Length !") if rio.length != 12 | |
throw Error("Tel Number is mandatory !") if notel == null | |
throw Error("Invalid Tel Number Length !") if notel.length != 10 | |
chk = exports.calcChksm(rio[0..1], rio[2], rio[3..8], notel) | |
if rio[9..11] == chk | |
return true | |
else | |
throw Error("Invalid RIO") | |
notel = prompt("N° de téléphone :") | |
if (notel) | |
rio = prompt("RIO :") | |
if (rio) | |
alert(exports.checkRIO(rio, notel)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment