package com.company;
import java.io.BufferedReader;
import java.io.InputStreamReader;
class Vernamcode
{ public static int getCharValue(char x)
{
int y=(int)'a';
return ((int)x-y);
}
public static char getNumberValue(int x)
{
int z=x+(int)'a';
return ((char)z);
}
public static void main(String args[])throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Ochiq matnni kiriting");
String accept=br.readLine();
System.out.println("\nOchiq matn o'lchamiga teng kalit kiriting");
String p=br.readLine();
int aqiy[]=new int[accept.length()];
int pqiy[]=new int[p.length()];
int initqiy[]=new int[p.length()];
if(p.length()!= accept.length())
{
System.out.println("Kalit xato.");
return;
}
for(int i=0;i{
int k=getCharValue(accept.charAt(i));
aqiy[i]=k;
}
for(int i=0;i
{
int k=getCharValue(p.charAt(i));
pqiy[i]=k;
}
for(int i=0;i
{
initqiy[i]=aqiy[i]+pqiy[i];
if(initqiy[i]>25)
initqiy[i]-=26;
}
System.out.println("\nShifrmatn : ");
String shifr="";
for(int i=0;i
{
shifr+=getNumberValue(initqiy[i]);
}
System.out.print(shifr);
}
}
Vijiner shifri. Birinchi bo’lib Vijiner tizimi 1586-yilda chop etilgan va u ko’p alifboli tizimga nisbatan Yuqoriroq o’rinda turadi. Bleza Vijinera o’zini XVI asrning fransuz diplomati deb hisoblaydi. U kriptografiya tizimiga, Ya’ni uning rivojlanishiga o’z hissasini qo’shgan. Vijiner tizimi Sezar shifrlash tizimiga qaraganda mukammalroq hisoblanib, unda kalit harfidan harfga almashtiriladi. Bunday ko’p alifboli almashtirish shifrini shifrlash jadvali orqali ifodalash mumkin. Quyidagi jadvallarda Vijinerning ingliz alifbosi va kiril alifbolari uchun mos keluvchi qiymatlar ko’rsatilgan.
package com.company;
import java.util.Scanner;
public class vijiner {
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]; } }}}
for (int i = 0; i length ; i++) {
System.out.print("kodlangan matn ");
System.out.print(kmatn[i]);
} }}
Do'stlaringiz bilan baham: |