Professional Documents
Culture Documents
Cryptography and Network Security Assignment 1) A Java Program For Shift Cipher
Cryptography and Network Security Assignment 1) A Java Program For Shift Cipher
Cryptography and Network Security Assignment 1) A Java Program For Shift Cipher
package shift_cipheredText;
import java.util.*;
public class cipheredText {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int yourNumber, size;
String letters="abcdefghijklmnopqrstuvwxyz";
String yourText, cipheredText="";
System.out.println("Enter the yourText: ");
yourText=sc.nextLine();
System.out.print("Enter the yourNumber: ");
yourNumber = sc.nextInt();
//int k=yourText.length();
//String[] cipheredText=new String[k];
for(int i=0;i<yourText.length();i++) {
char k = yourText.charAt(i);
letters="abcdefghijklmnopqrstuvwxyz";
if(Character.isUpperCase(k))
{
lettres="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
}
size = lettres.indexOf(yourText.charAt(i)) + yourNumber;
if(size > 25){
size = size % 26;
}
if(yourText.charAt(i)==' ')
{
cipheredText+=" ";
continue;
}
cipheredText = cipheredText + alphabet.charAt(size);
}
System.out.println(cipheredText);
}
}
2) a php program to imprement shift cipher
<?php
// intialize variables
$code = "";
$ki = 0;
$kl = strlen($pswd);
$length = strlen($text);
// lowercase
else
{
$text[$i] = chr(((ord($pswd[$ki]) - ord("a") + ord($text[$i]) -
ord("a")) % 26) + ord("a"));
}
// update the index of key
$ki++;
if ($ki >= $kl)
{
$ki = 0;
}
}
}
// intialize variables
$code = "";
$ki = 0;
$kl = strlen($pswd);
$length = strlen($text);
if ($x < 0)
{
$x += 26;
}
$x = $x + ord("A");
$text[$i] = chr($x);
}
// lowercase
else
{
$x = (ord($text[$i]) - ord("a")) - (ord($pswd[$ki]) - ord("a"));
if ($x < 0)
{
$x += 26;
}
$x = $x + ord("a");
$text[$i] = chr($x);
}
?>
import java.util.Scanner;
public class BruteForceAlgo {
public static void main(String[] args) {
Scanner t = new Scanner(System.in);
int m, j, l, k = 97, key = 0, flag = 0, intex = 0, keyVal;
String mytext;
char[] txt = new char[10];
char[] myText1 = new char[10];
char temp;
System.out.println("ENTER PLAIN TEXT");
p = t.next();
System.out.println("ENTER KEY VALUE :");
key = t.nextInt();
for (m = 0; i < mytext.length(); i++) {
for (j = 0; j < 26; j++) {
} else if (flag == 1) {
p1[i] = (char) ((26 + keyVal) + 97);
}
}
System.out.print("\n" + "DECRYPTED DATA:");
for (i = 0; i < m.length(); i++) {
System.out.print(myText1[i]);
}
key++;
}
}
}