SCAR Code:
{*******************************************************************************
function AddMistakes(Orig: string; Chance: Integer): string;
By: ZephyrsFury
Description: Adds human mistakes to Orig such as mistypes, missing letters,
wrong cases. Probability that a character is typed wrong is 1 / Chance. ie.
Higher 'Chance' = less mistakes (I know thats stupid but oh well...).
Probability is the chance that an individual character is typed incorrectly.
That is if you have more characters in a string you will get more mistakes overall.
20 - 30 is usually good but it varies depending on your string so experiment!
Use: TypeSend(AddMistakes('Hello', 20));
*******************************************************************************}
function AddMistakes(Orig: string; Chance: Integer): string;
var
Line1, Line2, Line: array [0..3] of string;
i, j, TPos, Prob, Mist, L: Integer;
Norm, Caps, Excp, TLine, NewKey: string;
begin
Norm := '`1234567890-=qwertyuiop[]\asdfghjkl;''zxcvbnm,./';
Caps := '~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:"ZXCVBNM<>?';
Excp := '`1234567890-=[]\;'',./~!@#$%^&*()_+{}|:"<>?';
Line1[0] := '`1234567890-= '; Line2[0] := '~!@#$%^&*()_+ ';
Line1[1] := ' qwertyuiop[]\'; Line2[1] := ' QWERTYUIOP{}|';
Line1[2] := ' asdfghjkl;'' '; Line2[2] := ' ASDFGHJKL:" ';
Line1[3] := ' zxcvbnm,./ '; Line2[3] := ' ZXCVBNM<>? ';
L := Length(Orig);
for i := 1 to L do
begin
Prob := Chance;
Prob := Prob + Mist; //More mistakes = less chance of another mistake
if (Pos(Orig[i], Excp) <> 0) then Prob := Prob - 2; //If char is hard to type (numbers/symbols) - more chance
if (i = 1) then Prob := Prob + 5; //The first letter - less chance
if (Orig[i] <> ' ') and (Random(Max(Prob, 0)) = 0) then
begin
if (Pos(Orig[i], Norm) <> 0) then
Line := Line1
else
if (Pos(Orig[i], Caps) <> 0) then
Line := Line2;
for j := 0 to 3 do
begin
TPos := Pos(Orig[i], Line[j]);
if (TPos <> 0) then
case Random(19) of
0..5: //Same line
begin
TLine := Line[j];
try
NewKey := TLine[TPos - 1 + Random(3)];
except end;
if (NewKey = '') or (NewKey = ' ') then
NewKey := TLine[TPos];
end;
6..8: //Line above
begin
TLine := Line[Max(j - 1, 0)]
try
NewKey := Line[j - 1][TPos + Random(2)];
except end;
if (NewKey = '') or (NewKey = ' ') then
NewKey := TLine[TPos];
end;
9..11: //Line below
begin
TLine := Line[Min(j + 1, High(Line))]
try
NewKey := TLine[TPos - 1 + Random(2)]; //Wrong case
except end;
if (NewKey = '') or (NewKey = ' ') then
NewKey := TLine[TPos];
end;
12..16:
begin
if (i - 1 >= 1) then
begin
if (Pos(Orig[i - 1], Caps) <> 0) then
NewKey := Line2[j][TPos]
else
if (Pos(Orig[i - 1], Norm) <> 0) then
NewKey := Line1[j][TPos]
end else
if (i + 1 <= Length(Orig)) then
begin
if (Pos(Orig[i + 1], Caps) <> 0) then
NewKey := Line2[j][TPos]
else
if (Pos(Orig[i + 1], Norm) <> 0) then
NewKey := Line1[j][TPos];
end;
end;
17, 18: if (i <> 1) then NewKey := ''; //Missing letters
end;
end;
end else
NewKey := Orig[i];
if (NewKey <> Orig[i]) then Inc(Mist);
Result := Result + NewKey;
end;
end;