Last active
July 11, 2016 19:49
-
-
Save ahmedengu/a03aecdbd4803dd9125a85dafb0447ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by ahmedengu. | |
*/ | |
object main { | |
def main(args: Array[String]) { | |
println("Enter the key:") | |
val key = scala.io.StdIn.readLine() | |
val matrix = Array.ofDim[Char](key.length, key.length) | |
println("Enter the PT") | |
val pt: String = scala.io.StdIn.readLine() | |
for (i <- 0 to pt.length-1) { | |
matrix(i/matrix.length)(i%matrix.length)=pt.charAt(i) | |
} | |
for (i<-key){ | |
for (j<-0 to matrix.length-1){ | |
print(matrix(j)(Integer.parseInt(i.toString) - 1)) | |
} | |
} | |
println("\nEnter Cipher:") | |
val m = Array.ofDim[Char](key.length, key.length) | |
val c : String = scala.io.StdIn.readLine() | |
var ci:Int = 0 | |
for (j<-key){ | |
for (i <- 0 to m.length-1) { | |
m(i)(Integer.parseInt(j.toString) - 1) = c.charAt(ci) | |
ci+=1 | |
} | |
} | |
for (i<-0 to m.length-1){ | |
for (j<-0 to m.length-1){ | |
print(m(i)(j)) | |
} | |
} | |
println() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Enter the key: | |
312 | |
Enter the PT | |
aoeuidhtn | |
ednauhoit | |
Enter Cipher: | |
ednauhoit | |
aoeuidhtn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment