Skip to content

Instantly share code, notes, and snippets.

@Zenithar
Created January 11, 2012 22:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Zenithar/1597257 to your computer and use it in GitHub Desktop.
Save Zenithar/1597257 to your computer and use it in GitHub Desktop.
French RIO Checksum and Check procedure
#
# 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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment