All pastes #2103530 Raw Edit

Miscellany

public text v1 · immutable
#2103530 ·published 2012-01-16 14:24 UTC
rendered paste body
/*
 * Created by SharpDevelop.
 * User: Jezzon
 * Date: 2012-01-15
 * Time: 02:20
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;

namespace ships
{
	/// <summary>
	/// Description of Xor.
	/// </summary>
	public class Xor
	{
		private static byte[] StrToByteArray(string str)
		{
			System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
			return encoding.GetBytes(str);
		}
		
		private static string ByteArrayToString(byte[] array)
		{
			System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
			string str = enc.GetString(array);
			return str;
		}
		public static string StrXOR(string str, string xor) {
			Byte[] tmpStr=StrToByteArray(str);
			Byte[] tmpXor=StrToByteArray(xor);
			for(int i=0;i<tmpStr.Length;i++)
				tmpStr[i]^=tmpXor[i];
			
			string res=ByteArrayToString(tmpStr);
			
			return res;
			
		}
		
		public Xor()
		{
		}
	}
}