Polybius Square Cipher | Java Program to implement polybius cipher ; Function to display polybius cipher text ; convert each character to its encrypted code ; finding row of the table ; finding column of the table ; if character is ' k ' ; if character is greater than ' j ' ; Driver code ; print the cipher of "geeksforgeeks
class GFG { static void polybiusCipher ( String s ) { int row , col ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { row = ( int ) Math . ceil ( ( s . charAt ( i ) - ' a ' ) / 5 ) + 1 ; col = ( ( s . charAt ( i ) - ' a ' ) % 5 ) + 1 ; if ( s . charAt ( i ) == ' k ' ) { row = row - 1 ; col = 5 - col + 1 ; } else if ( s . charAt ( i ) >= ' j ' ) { if ( col == 1 ) { col = 6 ; row = row - 1 ; } col = col - 1 ; } System . out . print ( row + " " + col ) ; } System . out . println ( ) ; } public static void main ( String [ ] args ) { String s = " geeksforgeeks " ; polybiusCipher ( s ) ; } }