Untitled
Never
playfair import java.util.Scanner; public class Playfair { public static void main(String args[]) { Scanner sc=new Scanner(System.in); String kw=sc.next(); String pt; char mat[]=new char[25]; char matrix[][]=new char[5][5]; int l,i,j,k,r1=0,r2=0,c1=0,c2=0; char c; mat[0]=kw.charAt(0); l=1; for(i=1;i<kw.length();i++) {System.out.println(kw.charAt(i)); for(j=0;j<l;j++) if (mat[j]==kw.charAt(i)) break; if (j==l) {mat[j]=kw.charAt(i);l++;} } for(c='A';c<91;c++) { if(c=='I') continue; //System.out.println(c); //compare and insert for(j=0;j<l;j++) if (mat[j]==c) break; if (j==l) {mat[j]=c;l++;} } for(j=0;j<25;j++) System.out.print(mat[j]+" "); k=0; for(i=0;i<5;i++) for(j=0;j<5;j++) {matrix[i][j]=mat[k++];} //printing in the matrix form for(i=0;i<5;i++) { System.out.println(); for(j=0;j<5;j++) System.out.print(matrix[i][j]+" "); } System.out.println("enter the plain text"); pt=sc.next(); char dg[]=new char[25]; char ct[]=new char[25]; dg[0]=pt.charAt(0); dg[1]=pt.charAt(1); for(i=0;i<25;i++) if(mat[i]==dg[0]) {r1=i/5;c1=i%5;} for(i=0;i<25;i++) if(mat[i]==dg[1]) {r2=i/5;c2=i%5;} if(r1==r2) {ct[0]=matrix[r1][(c1+1)%5]; ct[1]=matrix[r1][(c2+1)%5];} else if(c1==c2) {ct[0]=matrix[(r1+1)%5][c1]; ct[1]=matrix[(r2+1)%5][c2];} else {ct[0]=matrix[r2][c1]; ct[1]=matrix[r1][c2];} System.out.println(ct[0]+" "+ct[1]); } } hill cipher import java.util.Scanner; public class HillCipher { static int keyMat[][]=new int[3][3]; static void readKeyMatrix() {Scanner sc=new Scanner (System.in); int i,j; for(i=0;i<3;i++) for(j=0;j<3;j++) keyMat[i][j]=sc.nextInt(); } public static void main(String arg[]) { Scanner sc=new Scanner (System.in); String pt; System.out.print("enter the plain txt" ); pt=sc.next(); int i,l,m,ex; l=pt.length(); System.out.print(" enter how many characters ? "); m=sc.nextInt(); ex=l%m; int a[]=new int[l+ex]; for(i=0;i<l;i++) a[i]=(int)pt.charAt(i)-65; // filling extra values for(;i<l+ex;i++) a[i]=90; for(i=0;i<l+ex;i++) System.out.println(a[i]+" "); // multiplication part ciphertext readKeyMatrix(); int j,k; int p[][]=new int[m][1]; int c[][]=new int[m][1]; for(i=0;i<3;i++) p[i][0]=a[i]; for(i=0;i<3;i++) for(j=0;j<1;j++) {c[i][j]=0; for(k=0;k<3;k++) c[i][j]+=keyMat[i][k]*p[k][j]; } for(int n=0;n<3;n++) System.out.println((char)(c[n][0]%26+65)); } } caesar cipher class CeasarCipher { // Encrypts text using a shift of s public static StringBuffer encrypt(String text, int s) { StringBuffer result= new StringBuffer(); for (int i=0; i<text.length(); i++) { if (Character.isUpperCase(text.charAt(i))) { char ch = (char)(((int)text.charAt(i) + s - 65) % 26 + 65); result.append(ch); } else { char ch = (char)(((int)text.charAt(i) + s - 97) % 26 + 97); result.append(ch); } } return result; } // Driver code public static void main(String[] args) { String text = "cryptography"; int s = 3; System.out.println("Text : " + text); System.out.println("Shift : " + s); System.out.println("Cipher: " + encrypt(text, s)); } }
Raw Text
-
asdfghjk
34 sec ago
-
Untitled
1 min ago
-
Untitled
28 min ago
-
Untitled
33 min ago
-
Untitled
45 min ago
-
Untitled
1 hour ago
-
Breaking news - Update 1 - 12/10/2023 04:33:34
1 hour ago
-
~@~[[Official!]] Here's How To Watch NFL Week 14 Live Streams@ReddiT at Home?
1 hour ago
-
Breaking news - Update 1 - 12/10/2023 04:26:45
1 hour ago
-
wqegq3gwq3eg
1 hour ago