С революта няма такси освен ако не пращаш много големи суми
Първото не винаги е 1. Първото ти е цифрата на позиция 1. Последното число в контролната сума трябва да ти е 1.
Ето ти сметката, 30 за първото преобразуване е вярно @ .NET Fiddle
using System;
using System.Text;
namespace MyApp
{
public class Program
{
public static void Main(string[] args)
{
string input = "BG31UNCR70001523774937";
Console.WriteLine($"{nameof(input)}={input}");
string rearranged = input.Substring(4, input.Length - 4) + input.Substring(0, 4);
Console.WriteLine($"{nameof(rearranged)}={rearranged}");
StringBuilder sb = new StringBuilder();
foreach (var @char in rearranged)
{
int temp;
if (char.IsLetter(@char))
temp = @char - 55;
else
temp = short.Parse(@char.ToString());
sb.Append(temp);
}
var asciiCoded = sb.ToString();
Console.WriteLine($"{nameof(asciiCoded)}={asciiCoded}");
short checksum = short.Parse(asciiCoded.Substring(0, 1));
Console.WriteLine($"step 0; checksum={checksum}");
for (var i = 1; i < asciiCoded.Length; i++)
{
Console.WriteLine("---------");
Console.Write($"step {i}; ");
Console.Write($"checksum={checksum}; ");
Console.Write($"checksum = checksum*10 = {checksum}*{10} = ");
checksum *= 10;
Console.Write(checksum);
Console.Write($"; checksum = checksum+asciiCoded[{i}] = {checksum}+{asciiCoded.Substring(i, 1)} = ");
checksum += short.Parse(asciiCoded.Substring(i, 1));
Console.Write(checksum);
Console.Write($"; checksum = checksum%97 = {checksum}%97 = ");
checksum %= 97;
Console.WriteLine(checksum);
}
Console.WriteLine($"Is IBAN? {checksum == 1}");
}
}
}
Ще получиш резултат:
input=BG31UNCR70001523774937
rearranged=UNCR70001523774937BG31
asciiCoded=3023122770001523774937111631
step 0; checksum=3
---------
step 1; checksum=3; checksum = checksum*10 = 3*10 = 30; checksum = checksum+asciiCoded[1] = 30+0 = 30; checksum = checksum%97 = 30%97 = 30
---------
step 2; checksum=30; checksum = checksum*10 = 30*10 = 300; checksum = checksum+asciiCoded[2] = 300+2 = 302; checksum = checksum%97 = 302%97 = 11
---------
step 3; checksum=11; checksum = checksum*10 = 11*10 = 110; checksum = checksum+asciiCoded[3] = 110+3 = 113; checksum = checksum%97 = 113%97 = 16
---------
step 4; checksum=16; checksum = checksum*10 = 16*10 = 160; checksum = checksum+asciiCoded[4] = 160+1 = 161; checksum = checksum%97 = 161%97 = 64
---------
step 5; checksum=64; checksum = checksum*10 = 64*10 = 640; checksum = checksum+asciiCoded[5] = 640+2 = 642; checksum = checksum%97 = 642%97 = 60
---------
step 6; checksum=60; checksum = checksum*10 = 60*10 = 600; checksum = checksum+asciiCoded[6] = 600+2 = 602; checksum = checksum%97 = 602%97 = 20
---------
step 7; checksum=20; checksum = checksum*10 = 20*10 = 200; checksum = checksum+asciiCoded[7] = 200+7 = 207; checksum = checksum%97 = 207%97 = 13
---------
step 8; checksum=13; checksum = checksum*10 = 13*10 = 130; checksum = checksum+asciiCoded[8] = 130+7 = 137; checksum = checksum%97 = 137%97 = 40
---------
step 9; checksum=40; checksum = checksum*10 = 40*10 = 400; checksum = checksum+asciiCoded[9] = 400+0 = 400; checksum = checksum%97 = 400%97 = 12
---------
step 10; checksum=12; checksum = checksum*10 = 12*10 = 120; checksum = checksum+asciiCoded[10] = 120+0 = 120; checksum = checksum%97 = 120%97 = 23
---------
step 11; checksum=23; checksum = checksum*10 = 23*10 = 230; checksum = checksum+asciiCoded[11] = 230+0 = 230; checksum = checksum%97 = 230%97 = 36
---------
step 12; checksum=36; checksum = checksum*10 = 36*10 = 360; checksum = checksum+asciiCoded[12] = 360+1 = 361; checksum = checksum%97 = 361%97 = 70
---------
step 13; checksum=70; checksum = checksum*10 = 70*10 = 700; checksum = checksum+asciiCoded[13] = 700+5 = 705; checksum = checksum%97 = 705%97 = 26
---------
step 14; checksum=26; checksum = checksum*10 = 26*10 = 260; checksum = checksum+asciiCoded[14] = 260+2 = 262; checksum = checksum%97 = 262%97 = 68
---------
step 15; checksum=68; checksum = checksum*10 = 68*10 = 680; checksum = checksum+asciiCoded[15] = 680+3 = 683; checksum = checksum%97 = 683%97 = 4
---------
step 16; checksum=4; checksum = checksum*10 = 4*10 = 40; checksum = checksum+asciiCoded[16] = 40+7 = 47; checksum = checksum%97 = 47%97 = 47
---------
step 17; checksum=47; checksum = checksum*10 = 47*10 = 470; checksum = checksum+asciiCoded[17] = 470+7 = 477; checksum = checksum%97 = 477%97 = 89
---------
step 18; checksum=89; checksum = checksum*10 = 89*10 = 890; checksum = checksum+asciiCoded[18] = 890+4 = 894; checksum = checksum%97 = 894%97 = 21
---------
step 19; checksum=21; checksum = checksum*10 = 21*10 = 210; checksum = checksum+asciiCoded[19] = 210+9 = 219; checksum = checksum%97 = 219%97 = 25
---------
step 20; checksum=25; checksum = checksum*10 = 25*10 = 250; checksum = checksum+asciiCoded[20] = 250+3 = 253; checksum = checksum%97 = 253%97 = 59
---------
step 21; checksum=59; checksum = checksum*10 = 59*10 = 590; checksum = checksum+asciiCoded[21] = 590+7 = 597; checksum = checksum%97 = 597%97 = 15
---------
step 22; checksum=15; checksum = checksum*10 = 15*10 = 150; checksum = checksum+asciiCoded[22] = 150+1 = 151; checksum = checksum%97 = 151%97 = 54
---------
step 23; checksum=54; checksum = checksum*10 = 54*10 = 540; checksum = checksum+asciiCoded[23] = 540+1 = 541; checksum = checksum%97 = 541%97 = 56
---------
step 24; checksum=56; checksum = checksum*10 = 56*10 = 560; checksum = checksum+asciiCoded[24] = 560+1 = 561; checksum = checksum%97 = 561%97 = 76
---------
step 25; checksum=76; checksum = checksum*10 = 76*10 = 760; checksum = checksum+asciiCoded[25] = 760+6 = 766; checksum = checksum%97 = 766%97 = 87
---------
step 26; checksum=87; checksum = checksum*10 = 87*10 = 870; checksum = checksum+asciiCoded[26] = 870+3 = 873; checksum = checksum%97 = 873%97 = 0
---------
step 27; checksum=0; checksum = checksum*10 = 0*10 = 0; checksum = checksum+asciiCoded[27] = 0+1 = 1; checksum = checksum%97 = 1%97 = 1
Мога да ти пратя self-contained linux x64 executable за следния код:
using System;
using System.Collections.Generic;
namespace IsIban
{
public static class Program
{
public static void Main(string[] args)
{
Console.Write("Path of input file: ");
var path = Console.ReadLine();
Console.WriteLine();
Console.WriteLine($"Reading all ibans from file {path}");
if(!System.IO.File.Exists(path))
{
Console.WriteLine("File does not exist!");
return;
}
var lines = System.IO.File.ReadAllLines(path);
foreach(var item in lines)
{
var isIban = item
.RearangeIban()
.ToCalculationList()
.GetChechsum()
.IsValid();
Console.WriteLine($"{item} = {isIban}");
}
}
private static bool IsValid(this int input)
{
return input == 1;
}
private static int GetChechsum(this IList<int> input)
{
var checksum = input[0];
for(int i = 1; i < input.Count; i++)
{
checksum *= 10;
checksum += input[i];
checksum %= 97;
}
return checksum;
}
private static IList<int> ToCalculationList(this string input)
{
var result = new List<int>();
foreach (var item in input)
{
if (!char.IsLetter(item))
{
result.Add(item.ToInt32());
continue;
}
var temp = item - 55;
if (temp <= 9)
{
result.Add(item.ToInt32());
continue;
}
var tempString = temp.ToString();
result.Add(tempString[0].ToInt32());
result.Add(tempString[1].ToInt32());
}
return result;
}
private static int ToInt32(this char input)
{
return int.Parse(input.ToString());
}
private static string RearangeIban(this string input)
{
return input.Substring(4, input.Length - 4) + input.Substring(0, 4);
}
}
}
Няма да ти иска dependency-та. На дебиани ще тръгне ако са x86/x64. За ARM ще трябва да го прекомпилирам. run-ваш го, например
nekav@myshtaiga:/mnt/c/ConsoleApp4/IsIban/bin/Release/netcoreapp3.1/publish$ ls -la
total 35340
drwxrwxrwx 1 nekav nekav 4096 Dec 6 13:38 .
drwxrwxrwx 1 nekav nekav 4096 Dec 6 13:26 ..
-rwxrwxrwx 1 nekav nekav 2230 Dec 6 13:13 ibans
-rwxrwxrwx 1 nekav nekav 36183533 Dec 6 13:26 IsIban
nekav@myshtaiga:/mnt/c/ConsoleApp4/IsIban/bin/Release/netcoreapp3.1/publish$ ./IsIban
Path of input file: ibans
Reading all ibans from file ibans
BG92UBBS80021088489340 = True
BG45UBBS80021091670040 = True
BG62TTBB94001528480941 = True
BG47UNCR70001523776977 = True
BG65RZBB91551009352869 = True
BG51TTBB94001527702326 = True
BG96TTBB94001528743490 = True
BG19RZBB91551011398942 = True
BG06STSA93001528484951 = True
BG40RZBB91551009680791 = True
BG49STSA93001528741421 = True
BG58TTBB94001527702685 = True
BG03STSA93000025186086 = True
BG85UBBS80021083643540 = True
BG38STSA93001528781971 = True
BG50TTBB94001527701956 = True
BG46STSA93000026213706 = True
BG84RZBB91551010887358 = True
BG94STSA93000025737348 = True
BG16UBBS80021093947540 = True
BG20STSA93000026499257 = True
BG48UBBS80021088486640 = True
BG95UBBS80021088487540 = True
BG18UNCR70001523431015 = True
BG20STSA93000026427574 = True
BG92TTBB94001527703140 = True
BG40UBBS80021088675740 = True
BG65STSA93001528750639 = True
BG91TTBB94001527702673 = True
BG12TTBB94001527702252 = True
BG14TTBB94001528131053 = True
BG14TTBB94001527701731 = True
BG44STSA93000025601575 = True
BG58STSA93000000243486 = True
BG26TTBB94001527702291 = True
BG39UBBS80021088482340 = True
BG02STSA93001528135435 = True
BG07TTBB94001528229149 = True
BG19UNCR70001523802022 = True
BG24STSA93000025179500 = True
BG17TTBB94001527702356 = True
BG38TTBB94001528653742 = True
BG77STSA93000026047860 = True
BG97UBBS80021088631840 = True
BG13TTBB94001527701943 = True
BG42RZBB91551008580484 = True
BG49STSA93000025721765 = True
BG51STSA93000025781869 = True
BG16UBBS80021088486440 = True
BG93RZBB91551097956530 = True
BG04STSA93000025737319 = True
BG52TTBB94001528774158 = True
BG35UBBS80021088455640 = True
BG70STSA93000025733609 = True
BG11STSA93000025118624 = True
BG58TTBB94001528743398 = True
BG66UBBS80021088456440 = True
BG69STSA93000027143231 = True
BG88TTBB94001528770794 = True
BG86UBBS80021088677240 = True
BG31UNCR70001523774937 = True
BG44TTBB94001527702355 = True
BG90STSA93000025743919 = True
BG36UBBS80021091830640 = True
BG64TTBB94001527702771 = True
BG06RZBB91551009391567 = True
BG86UBBS80021089230140 = True
BG54UBBS80021091887740 = True
BG78TTBB94001527702713 = True
BG10STSA93000027041570 = True
BG34RZBB91551011773771 = True
BG15STSA93000025520229 = True
BG34RZBB91551010904748 = True
BG04UBBS80021089046540 = True
BG27TTBB94001527702758 = True
BG16TTBB94001528464309 = True
BG21TTBB94001527702284 = True
BG62STSA93000025158931 = True
BG66TTBB94001527702056 = True
BG52UNCR70001523692594 = True
BG15UBBS80021091891740 = True
BG40TTBB94001528737514 = True
BG07UBBS80021088482140 = True
BG79UNCR70001523414494 = True
BG17TTBB94001527701677 = True
BG88STSA93000026043588 = True
BG04UBBS80021088939840 = True
BG22UNCR70001523787321 = True
BG26TTBB94001527703067 = True
BG09STSA93001528741171 = True
BG05STSA93001528509995 = True
BG11TTBB94001527702658 = True
BG73RZBB91551007969893 = True
nekav@myshtaiga:/mnt/c/ConsoleApp4/IsIban/bin/Release/netcoreapp3.1/publish$
Друг вариант е да си инсталираш netcore 3.1 sdk и да си го компилираш сам.