encryption - C# Index exception unhandeled -


so i'm doing school project. small program encrypting passwords in both directions , i'm stuck in coding encrypted normal version. should read 2 2 chars of encrypted version, replace them matching char , return string. cause each char in original pass replaced 2 chars in encrypted version, ,., .., or similar. here i'm stuck , no matter following exception doesn't go away

else {     string target;     text = "";     password = richtextbox2.text;     (int = 0; <= password.length; += 2)     {         target = convert.tostring(password[i])             + convert.tostring(password[i + 1]);         if (target == ",,")         {             text += "a";         }     }     richtextbox3.text = text; } 

off 1 error. because test i <= password.length, you'll enter loop when i equal password.length, cause outofboundsexception when try password[i] - because strings 0 based indexed, should stop before occurs. in case, change <= <:

for (int = 0; <= password.length - 1; += 2) 

edit i've added check against password.length - 1 because access password[i + 1], same problem

it might helpful add checks , ensure password has number of characters, or run same issue since you're incrementing 2.


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -