initial commit
initial commit

file:b/php/cnp.php (new)
--- /dev/null
+++ b/php/cnp.php
@@ -1,1 +1,42 @@
+<?php
 
+/*
+
+Validare de CNP
+
+1) se calculeaza suma
+s:=c(1)*2+c(2)*7+c(3)*9+c(4)*1+c(5)*4+c(6)*6+c(7)*3+c(8)*5+c(9)*8+c(10)*2+c(11)*7+c(12)*9
+2) faci impartirea
+rest=s%11
+3) dupa cum:
+- rest<10 at c(13)=rest
+sau
+- rest=10 at c(13)=1
+
+
+*/
+
+$cnp = "2851210278792";
+
+if ( calcCNP ( $cnp ) ) {
+    echo $cnp." e valid";
+} else {
+    echo $cnp." e invalid";
+}
+
+function calcCNP ($cnp) {
+    if ( strlen ($cnp) != 13 ) {
+        return false;
+    }
+    
+    $s = $cnp{0}*2+$cnp{1}*7+$cnp{2}*9+$cnp{3}*1+$cnp{4}*4+$cnp{5}*6+$cnp{6}*3+$cnp{7}*5+$cnp{8}*8+$cnp{9}*2+$cnp{10}*7+$cnp{11}*9;
+    $rest = $s%11;
+    if ( $rest >= 10 ) $rest=1;
+    if ( $cnp{12} == $rest ) {
+        return true;
+    } else {
+        return false;
+    }
+}
+
+?>

file:b/php/cui.php (new)
--- /dev/null
+++ b/php/cui.php
@@ -1,1 +1,22 @@
+<?php 
 
+function isCui ($cif) {
+    if (!is_numeric($cif)) return false;
+    if ( strlen($cif)>10 ) return false;
+    $cifra_control=substr($cif, -1);
+    $cif=substr($cif, 0, -1);
+    while (strlen($cif)!=9){
+        $cif='0'.$cif;
+    }
+    $suma=$cif[0] * 7 + $cif[1] * 5 + $cif[2] * 3 + $cif[3] * 2 + $cif[4] * 1 + $cif[5] * 7 + $cif[6] * 5 + $cif[7] * 3 + $cif[8] * 2;
+    $suma=$suma*10;
+    $rest=fmod($suma, 11);
+    if ( $rest==10 ) $rest=0;
+    if ( $rest == $cifra_control ) {
+        return true;
+    } else {
+        return false;
+    }
+}
+
+?>

comments