Polybius Square is a table that allows someone to translate letters into numbers. To give a small level of encryption, this table can be randomized and shared with the recipient. In order to fit the 26 letters of the alphabet into the 25 spots created by the table, the letters i and j are usually combined.

1 2 3 4 5
1 A B C D E
2 F G H I K
3 L M N O P
4 Q R S T U
5 V W X Y Z
To encipher a message you replace each letter with the row and column in which it appears. For example, D would be replaced with 14.

To decipher a message you find the letter that intersects the specified row and column.

Example:

Plaintext: This is a secret message
Ciphertext: 44232443 2443 11 431513421544 32154343112215
pls help with this or give me clue for this program

Recommended Answers

All 3 Replies

1.First, you need to create a table to store your letters. You could use a 2 dimensional array of 5x5.

2.Second, you need to be able to search for the position of the letter inside the table given a character. The function should return a string of (row+1)+""+(col+1) which is the location found in the letter table.

3.Last, you need to iterate through all character in a given string. If the character is a letter, then encrypt the letter by calling the function to search for the letter location in the letter table and display the encrypt result. If the character is not a letter, then just display the character.

import java.io.*;
class polybius
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
char alpha[][]={{'A','B','C','D','E'},{'F','G','H','I','J'},{'K','L','M','N','O'},{'P','Q','R','S','T'},{'U','V','W','Y','Z'}};String str;
public void input()throws IOException
{
System.out.println("ENTER STRING");
str=br.readLine();



for(int i=0;i<5;i++)
{
for(int j=0;j<5;j++)
{
System.out.print(alpha[i][j]+" ");
}
System.out.println();
}
}
public int search(char ch)throws IOException
{

int i,j;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(ch==alpha[i][j]);
return((i+1)+" "+(j+1));
}
}
}
public void iterate()
{
int len=str.length();
int a;char ch1;
for(a=0;a<len;a++)
{
ch1=str.charAt(a);
if(Character.isLetter(ch1))
{
System.out.print(search(ch1));
}
if(Character.isDigit(ch1))
{
System.out.print(ch1);
}
if(Character.isSpacechar(ch1))
{
System.out.print(ch1);
}
}}
public void main()throws IOException
{
polybius ob=new polybius();
ob.input();
ob.iterate();
}
}

the error is incompatible types found java.lang but expected int....pls help

error is in line 31

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.