Skip to content

Instantly share code, notes, and snippets.

@AsifMushtaq
Last active August 29, 2015 13:56
Show Gist options
  • Save AsifMushtaq/9207923 to your computer and use it in GitHub Desktop.
Save AsifMushtaq/9207923 to your computer and use it in GitHub Desktop.
Missing Letter Puzzel Im
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MissingWordPuzzel
{
class Program
{
static void Main(string[] args)
{
var asciiValues = GetDecimalEquivalent("Hello");
var stegoFile = string.Empty;
var stegoKey = string.Empty;
foreach (var n in asciiValues)
{
int flag;
int q, r, l;
string word;
if (n < 100)
{
flag = 0;
q = n / 10;
r = n % 10;
l = q < 6 ? 10 + q : q;
word = GetWord(l);
if (r == 0)
{
word = MissTheCharactorAt(word, new Random().Next(0, l));
}
else if (r <= q)
{
word = MissTheCharactorAt(word, r);
}
else
{
word = MissTheCharactorAt(word, r - q);
int[] range = new[] { 6, 7, 8, 9 };
int index = range.Contains(q) ? new Random().Next(4, l) : new Random().Next(10, l);
word = MissTheCharactorAt(word, index);
}
}
else
{
flag = 1 + LeastSignificantDigit(n);
q = MostSignificantDigit(n);
r = MiddleDigit(n);
l = 10 + q;
word = GetWord(l);
if (r == 0)
{
word = MissTheCharactorAt(word, new Random().Next(10, l));
}
else
{
word = MissTheCharactorAt(word, r);
}
}
stegoFile += word + " ";
stegoKey += flag + " ";
}
Console.WriteLine(stegoFile);
Console.WriteLine(stegoKey);
Console.ReadKey();
}
private static int CaclculateLength(string input)
{
return input.Count();
}
private static int[] GetDecimalEquivalent(string input)
{
return input.Select(c => (int)c).ToArray();
}
private static string GetWord(int lettersCount)
{
var text = "abcdefghijklmnopqrstuvwxyz";
Random random = new Random();
char[] chars = Enumerable.Range(0, lettersCount)
.Select(c => text[random.Next(0, 26)])
.ToArray();
return new String(chars);
}
private static string MissTheCharactorAt(string word, int index)
{
var chars = word.ToCharArray();
chars[index] = '?';
return new string(chars);
}
private static int LeastSignificantDigit(int value)
{
return value % 10;
}
private static int MostSignificantDigit(int value)
{
return value / 100;
}
private static int MiddleDigit(int value)
{
return (value / 10) % 10;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment