6-amaliy ish Kriptografiya 1 Mavzu: Psevdotasodifiy sonlar generatorini va uning dasturiy ta’minotini yaratish
Download 65.81 Kb.
|
6-amaliy,kriptografiya 1
6-amaliy ish Kriptografiya_1 Mavzu: Psevdotasodifiy sonlar generatorini va uning dasturiy ta’minotini yaratish. Chiziqli va chiziqsiz kongurent kalit xosil qilishning dasturiy ta’minotini ishlab chiqishda Java dasturlash tilidan foydalandim. package com.company; import java.nio.charset.StandardCharsets; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner km=new Scanner(System.in); char generatsiyaturi; System.out.println("Kalitni generatsiya qilish turini tanglang!\na tugmani bossangiz chiziqli kongurent rejimni tanlagan bo'lasiz!\nb tugmani bossangiz chiziqsiz kongurent rejimni tanlagan bo'lasiz!"); String k =km.nextLine().toLowerCase(); int w=0;
int t=0; generatsiyaturi=k.charAt(0); switch (generatsiyaturi){ case 'a': w++; System.out.println(" Siz chiziqli kongurent rejimni tanladingiz!! va\nX(i+1)=(aXi+c)mod N: formula bo'yicha kalit generatsiya qilinadi "); break; case 'b': System.out.println("Siz chiziqsiz kongurent rejimni tanladingiz!! va\nX(i+1)=(d(Xi)^2+aXi+c)mod N: formula bo'yicha kalit generatsiya qilinadi"); t++; break; } if (t==1){ System.out.print("xo ni kiriting="); int xo= km.nextInt(); System.out.print("d ni kiriting="); int d=km.nextInt(); System.out.print("a ni kiriting="); int a=km.nextInt(); System.out.print("c ni kiriting="); int c=km.nextInt(); int n=9; System.out.print("Eslatma! kalit uzunligi 8 bitdan kam bo'lmasiligi kerak va 8ga karrali bo'lsin!\nkalit uzunligini kiriting yani necha bit bo'lsin!!="); int kk=km.nextInt(); int sonlar_soni=kk/8; int ll=sonlar_soni*8; int sonlar[]=new int[sonlar_soni]; sonlar[0]=xo; for (int i = 1; i sonlar[i]=(d*(int) Math.pow(i,2)+(sonlar[i-1]*a)+c)%n; }
System.out.print("K= "); for (int i = 0; i // System.out.print( sonlar[i] + " "); String input= String.valueOf(sonlar[i]);
String result=convertByteArraysToBinary(input.getBytes(StandardCharsets.UTF_8)); System.out.print(result);
}
System.out.print (" "+ll+" bitlik kalit"); System.out.print("xo ni kiriting="); int xo= km.nextInt();
System.out.print("a ni kiriting="); int a=km.nextInt();
System.out.print("c ni kiriting="); int c=km.nextInt();
int n=9;
int kk=km.nextInt(); int sonlar_soni=kk/8;
int ll=sonlar_soni*8; int sonlar[]=new int[sonlar_soni];
sonlar[0]=xo; for (int i = 1; i sonlar[i]=((sonlar[i-1]*a)+c)%n; } System.out.print("K= ");
for (int i = 0; i // System.out.print(sonlar[i] + " ");
String input= String.valueOf(sonlar[i]); String result=convertByteArraysToBinary(input.getBytes(StandardCharsets.UTF_8));
System.out.print(result); }
System.out.print (" "+ll+" bitlik kalit"); }
public static String convertByteArraysToBinary(byte[] input) { for (byte b : input) { int val = b;
for (int i = 0; i < 8; i++) { result.append((val & 128) == 0 ? 0 : 1); // 128 = 1000 0000
val <<= 1; }
|
ma'muriyatiga murojaat qiling