Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
TC Kimlik No Uretme Kodu (Java)
package com.kodfarki.chargeback;
import org.junit.Test;
/**
* User: Halil Karakose
* Date: 2019-12-22
* Time: 15:38
*/
public class TcKimlikTest {
@Test
public void tcKimlikOlustur() {
Integer pool1 = new Double(Math.floor(Math.random() * 90000 + 10000)).intValue();
String[] p1Chars = toStringArray(pool1);
System.out.println("poo1 = " + pool1);
Integer pool1Sum = arraySum(p1Chars);
System.out.println("pool1Sum = " + pool1Sum);
Integer pool2 = new Double(Math.floor(Math.random() * 9000 + 1000)).intValue();
String[] p2Chars = toStringArray(pool2);
System.out.println("poo1 = " + pool2);
Integer pool2Sum = arraySum(p2Chars);
System.out.println("pool2Sum = " + pool2Sum);
int digit10 = calculateDigit10(pool1Sum, pool2Sum);
int digit11 = calculateDigit11(pool1Sum, pool2Sum, digit10);
String tckn = p1Chars[0] + p2Chars[0] + p1Chars[1] + p2Chars[1] + p1Chars[2] + p2Chars[2] + p1Chars[3] + p2Chars[3] + p1Chars[4] + digit10 + digit11;
System.out.println("tckn = " + tckn);
}
private String[] toStringArray(Integer integer) {
String string = integer.toString();
char[] chars = string.toCharArray();
String[] strings = new String[chars.length];
for (int i = 0; i < chars.length; i++) {
strings[i] = chars[i] + "";
}
return strings;
}
private int calculateDigit11(int pool1Sum, int pool2Sum, int digit10) {
return (pool1Sum + pool2Sum + digit10) % 10;
}
private int calculateDigit10(Integer pool1Sum, Integer pool2Sum) {
int i = pool1Sum * 7;
int digit10 = (i - pool2Sum) % 10;
return digit10;
}
private Integer arraySum(String[] arr) {
Integer sum = 0;
for (int i = 0; i < arr.length; i++) {
sum += new Integer(arr[i]);
}
return sum;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment