# Verifying a sedamo Address Code

The first digit of the sedamo address code is a check digit which allows to verify the code without an API call.

The check digit is the modulo (the rest of an integer division) by 20, where A=0, B=1, C=2, D=3, E=4, F=5, G=6, H=7, J=8, K=9, L=10, M=11, P=12, Q=13, R=14, T=15, U=16, W=17, X=18, Y=19. Please note that the letters I, N, O, S, V, and Z are not used in a sedamo address code. Each digit must be multiplied by its position, starting with 0.

##### Examples
`AB-CD-EF-GH`

1st digit: *0, 2nd digit: *1 and so on:

`A*0 + B*1 + C*2 + D*3 + E*4 + F*5 + G*6 + H*7`

A=0, B=1 etc. So:

```0*0 + 1*1 + 2*2 + 3*3 + 4*4 + 5*5 + 6*6 + 7*7
= 140
140 : 20 = 7, rest 0
0 = A ```

“A” is the check digit (first letter of the code). This sedamo address code is correct!

`FC-KN-AZ-IS`

This code is obviously wrong, a sedamo address code cannot contain the letters “N”, “Z”, “I”, and “S”.

```CT-QP-DE-TP

C*0 + T*1 + Q*2 + P*3 + D*4 + E*5 + T*6 + P*7
= 2*0 + 15*1 + 13*2 + 12*3 + 3*4 + 4*5 + 15*6 + 12*7
= 283
283 : 20 = 14, rest 3
3 = D
D ≠ C```

Check digit and calculated check sum do not match, this code is incorrect. (A letter error occurred during the input, D and E were interchanged. The correct code would be `CT-QP-ED-TP`.)

##### PHP function

Here is a PHP function to check the correctness of a sedamo address code. (Please remove hyphens, dots, spaces etc. from the address code before testing!)

sedamo_code_verification.php
```function is_sedamo(\$sedamo)
{  // verifies the check digit of the sedamo address code
\$letters = array("A"=>0, "B"=>1, "C"=>2, "D"=>3, "E"=>4, "F"=>5, "G"=>6, "H"=>7, "J"=>8, "K"=>9, "L"=>10, "M"=>11, "P"=>12, "Q"=>13, "R"=>14, "T"=>15, "U"=>16, "W"=>17, "X"=>18, "Y"=>19); // 20 characters

if  (strlen(\$sedamo) != 8) { return(false); }
else {
for(\$i=1, \$sum=0; \$i<8; \$i++)
{
\$sum = \$sum  + \$i * \$letters[(\$sedamo[(\$i)])];
} // for
return (fmod(\$sum, 20) == \$letters[(\$sedamo[0])]);
} // if-else
} // is_sedamo```