Sezar shifrlash usuli Java dasturlash tilida
package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner km= new Scanner(System.in);
System.out.print("matnni kiriting=");
String matn1 = km.nextLine();
System.out.print("KALIT(alifboni surishsoni)=");
int surishsoni1 = km.nextInt();
String shifrmatn = "";
char alifboharfi;
for(int i=0; i < matn1.length();i++)
{ alifboharfi = matn1.charAt(i);
//agar harfimiz kichik harf bo'lsa
if(alifboharfi >= 'a' && alifboharfi <= 'z')
{ alifboharfi = (char) (alifboharfi + surishsoni1);
if(alifboharfi > 'z') { alifboharfi = (char) (alifboharfi+'a'-'z'-1);}
shifrmatn =shifrmatn + alifboharfi;}
//Agar harfimiz katta harf bo'lsa
else if(alifboharfi >= 'A' && alifboharfi <= 'Z') { alifboharfi = (char) (alifboharfi + surishsoni1);
if(alifboharfi > 'Z') {alifboharfi = (char) (alifboharfi+'A'-'Z'-1);}
shifrmatn = shifrmatn + alifboharfi; }
else {shifrmatn = shifrmatn + alifboharfi;}}
System.out.println("Shifrmatn : " + shifrmatn);
}}
Dastur natijasi:
Vernam shifrlash usuli Java dasturlash tilida
package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner km = new Scanner(System.in);
System.out.print("textni kiriting = ");
String text = km.nextLine();
char textmassiv[] = text.toCharArray();
System.out.print("kalitni kiriting = ");
String kalit = km.nextLine();
char kalitmassiv[] = kalit.toCharArray();
char[] shifrtext = new char[text.length()];
System.out.println("textimiz => " + text + " => Uzunligi=" + text.length()+" ga teng");
if (text.length() < kalit.length()) {
String C = "";
for (int i = 0;ikalit = C;}
int j = kalit.length();
while (kalit.length() < text.length()) {
for (int i = 0; i < j; i++) {
kalit = kalit + kalitmassiv[i];
if (kalit.length() == text.length()) break;}}
System.out.println("kalitimiz => " + kalit + " => Uzunligi=" + kalit.length()+" ga teng");
char kalitoxirginatijasi[] = kalit.toCharArray();
System.out.print("shifrtextimiz => ");
for (int i = 0; i < textmassiv.length; i++) {
shifrtext[i] = (char) (textmassiv[i] ^ kalitoxirginatijasi[i]);
System.out.print(shifrtext[i]);}
System.out.print(" => Uzunligi="+shifrtext.length+" ga teng");
}}
Dastur natijasi:
Vijiner shifrlash usuli Java dasturlash tilida
package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
char alifbo[]=new char[26], kalif[]=new char[26];
for (char i=0,j= 'A'; j<='Z' ; i++,j++) {
alifbo[i]=j; }
Scanner x=new Scanner(System.in);
String kalit, ochmatn;
System.out.print("kodlanadigon matnni kiriting ");
ochmatn=x.nextLine();
System.out.print("kalitni kiriting ");
kalit=x.nextLine();
char kt[]=kalit.toCharArray(), ochm[]=ochmatn.toCharArray(),
um[]=new char[ochmatn.length()], kmatn[]=new char[ochmatn.length()];
for (char j=0,i = 0; i length ;j++, i++) {
um[i]=kt[(j+kt.length)%kt.length]; }
for (char i = 0; i length ; i++)
for (char j = 0; j length ; j++) {
if (um[i]==alifbo[j]){
for (char l=j, k = 0; k length ;l++, k++) {
kalif[k]=alifbo[l%26]; }
for (int k = 0; k length ; k++)
for (int l = 0; l < alifbo.length; l++) {
if (ochm[i]==alifbo[l]){
kmatn[i]=kalif[l]; } }}}
System.out.print(" Shifrmatn = ");
for (int i = 0; i length ; i++) {
System.out.print(kmatn[i]);
}
}}
DASTUR NATIJASI:
Do'stlaringiz bilan baham: |