Advertisement
Guest User

Untitled

a guest
Jan 25th, 2021
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.75 KB | None | 0 0
  1. public static class InnGenerator {
  2.  
  3.         private long inn12;
  4.         private boolean inn_true;
  5.         private  byte[] spep10 = {2, 4, 10, 3, 5, 9, 4, 6, 8};
  6.         private  byte[] spep12_n2 = {7, 2, 4, 10, 3, 5, 9, 4, 6, 8};
  7.         private  byte[] spep12_n1 = {3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8};
  8.  
  9.         public boolean isInn_true() {
  10.             return inn_true;
  11.         }
  12.  
  13.         public long getInn12() {
  14.             return inn12;
  15.         }
  16.  
  17.         public boolean bool;
  18.  
  19.         public InnGenerator(long a) {
  20.             bool = this.Check_inn(a);
  21.         }
  22.  
  23.         public InnGenerator(int i) {
  24.             if (i == 12) {
  25.                 inn_true = false;
  26.                 while (inn_true != true) {
  27.                     inn12 = Inn_12_gen();
  28.                     inn_true = Check_inn(inn12);
  29.                 }
  30.             }
  31.         }
  32.  
  33.         private long Inn_12_gen() {
  34.             long gen12 = 100000000000L + (long) (Math.random() * 899999999999L);
  35.             return gen12;
  36.         }
  37.  
  38.         private boolean Check_inn(long in) {
  39.             String str = String.valueOf(in);
  40.  
  41.             if (str.length() == 12) {
  42.                 int sum_12 = 0;
  43.                 int control_number = 0;
  44.                 for (int i = 0; i < spep10.length; i++) {
  45.                     sum_12 = sum_12 + (Integer.parseInt(String.valueOf(str.charAt(i))) * spep10[i]);
  46.                 }
  47.                 if (sum_12 % 11 == 10) control_number = 0;
  48.                 else control_number = sum_12 % 11;
  49.  
  50.                 if (control_number == Integer.parseInt(String.valueOf(str.charAt(9)))) return true;
  51.                 else return false;
  52.             } else if (str.length() == 12) {
  53.                 int sum_12_2 = 0;
  54.                 int control_number_n1 = 0;
  55.                 int control_number_n2 = 0;
  56.  
  57.                 for (int i = 0; i < spep12_n2.length; i++) {
  58.                     sum_12_2 = sum_12_2 + (Integer.parseInt(String.valueOf(str.charAt(i))) * spep12_n2[i]);
  59.                 }
  60.  
  61.                 if (sum_12_2 % 11 == 10) control_number_n2 = 0;
  62.                 else control_number_n2 = sum_12_2 % 11;
  63.  
  64.                 int sum_12 = 0;
  65.                 for (int j = 0; j < spep12_n1.length; j++) {
  66.                     sum_12 = sum_12 + (Integer.parseInt(String.valueOf(str.charAt(j))) * spep12_n1[j]);
  67.                 }
  68.                 if (sum_12 % 11 == 10) control_number_n1 = 0;
  69.                 else control_number_n1 = sum_12 % 11;
  70.  
  71.                 if ((control_number_n1 == Integer.parseInt(String.valueOf(str.charAt(11))))
  72.                         && (control_number_n2 == Integer.parseInt(String.valueOf(str.charAt(10)))))
  73.                     return true;
  74.                 else return false;
  75.             } else return false;
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement