Skip to content

Instantly share code, notes, and snippets.

@rivsc
Last active October 25, 2019 13:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rivsc/f8c74f32a24958efb7b6a0c4447a774e to your computer and use it in GitHub Desktop.
Méthode de calcul de la clé RIB (relevé d'identité bancaire)
# Methode de calcul de la clé RIB (relevé d'identité bancaire)
# le calcul vient de wikipedia fr
def cle_rib(code_banque, code_guichet, numero_compte)
mapping = ["", "AJ", "BKS", "CLT", "DMU", "ENV", "FOW", "GPX", "HQY", "IRZ"]
numero_compte.scan(/[A-Z]/).each do |ch|
mapping.each_with_index do |str, i|
if str.include?(ch)
numero_compte = numero_compte.gsub(ch, i.to_s)
break
end
end
end
97 - ((89 * code_banque.to_i + 15 * code_guichet.to_i + 76 * numero_compte[0..5].to_i + 3 * numero_compte[6..-1].to_i) % 97)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment