c# - Merging two lines of code into one -
byte[] p = asciiencoding.ascii.getbytes(password); byte[] p = new byte[8]
i need define size of array , keep first line of code @ same time. error when write them both, because p array defined twice. how can this?
this code whole
public string hasher(string password, string id) { try { byte[] p = asciiencoding.ascii.getbytes(password); byte[] a6 = asciiencoding.ascii.getbytes(id); byte totvector = 0; (int = 0; < 8; i++) { totvector = (byte)(totvector + p[i]); } byte[] a_concat = new byte[2]; a_concat[0] = (byte)((p[6] * totvector) % 256); a_concat[1] = (byte)((p[7] * totvector) % 256); byte[] = new byte[8]; (int = 0; < 6; i++) { a[i] = a6[i]; } a[6] = a_concat[0]; a[7] = a_concat[1]; byte[] h = new byte[8]; string hasheduserpassword = ""; (int = 0; < 8; i++) { if (i == 0 || == 2) h[i] = (byte)((p[i] << 1) ^ a[i]); else if (i == 3 || == 5) h[i] = (byte)((p[i] >> 2) ^ a[i]); else h[i] = (byte)(p[i] ^ a[i]); hasheduserpassword += h[i].tostring("x2"); } return hasheduserpassword; } catch { return "error"; } }
the primary problem right here:
(int = 0; < 8; i++) { totvector = (byte)(totvector + p[i]); }
the easiest fix not try 8 iterations if array doesn't have many items. calculate length first:
int len = math.min(p.length, 8); // limit no more length (int = 0; < len; i++) { totvector = (byte)(totvector + p[i]); }
Comments
Post a Comment