My text has 6 letters, my key has 4 letters. After XOR I get newText with only 4 letters. How can I make my key longer (repeat it till text length?
for ex.: string text = "flower",string key = "hell" I want to make my string key = "hellhe" and so on...)
private string XorText(string text,string key)
{
string newText = "";
for (int i = 0; i < key.Length; i++)
{
int charValue = Convert.ToInt32(text[i]);
int keyValue = Convert.ToInt32(key[i]);
charValue ^= keyValue % 33;
newText += char.ConvertFromUtf32(charValue);
}
return newText;
}
key[i]usekey[i%key.Length]and change yourforloop to usei < text.Length. Look up "modulus" to see how this works.