Does anyone know how to write a simple code for cryptogram puzzles for a website? You enter a passage and then encrypt the passage to become numbers. You type "hello" and it would come out to be:
_ _ _ _ _
2 6 8 8 10
Thanks for any help.
Cryptogram Puzzle help
Started by Renee55, Aug 28 2010 12:05 PM
1 reply to this topic
#1
Posted 28 August 2010 - 12:05 PM
|
|
|
#2
Posted 28 August 2010 - 02:29 PM
Just something I threw together, to give you an idea. Most of the code deals with formatting :)
static String Crypto(String source) {
StringBuilder sb = new StringBuilder();
char[] ca = source.ToUpper().ToCharArray();
int[] code = Shuffled();
foreach (char c in ca) {
if (c < 'A' || c > 'Z') {
if (c == ' ') {
sb.Append(' ');
}
sb.Append(c);
} else {
sb.Append(' ');
sb.Append(code[c-'A']).ToString();
}
}
return sb.ToString().Trim();
}
static int[] Shuffled() {
int j;
int temp;
int[] result = new int[26];
Random r = new Random();
for (int i = 0; i < result.Length; i++) {
result[i] = i + 1;
}
for (int i = result.Length - 1; i > 0; i--) {
j = r.Next(i);
temp = result[i];
result[i] = result[j];
result[j] = temp;
}
return result;
}


Sign In
Create Account

Back to top









