Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.
Become a Premium Member and unlock a new, free course in leading technologies each month.
function VigenereExEncrypt(sSource, sKey: String; bDecrypt: Boolean = False; iTableSize: Integer = 94): String;
var
i, iPosText, iPosKey: Integer;
sTable: string;
begin
i:= 32;
while i <= (iTableSize + 32) do
begin
sTable:= ConCat(sTable, Chr(i));
inc(i);
end;
while Length(sSource) >= Length(sKey) do
sKey:= ConCat(sKey,sKey);
i:=0;
while i<=Length(sSource) do
if (sSource[i]=Chr(10)) or (sSource[i]=Chr(13)) then
Delete(sSource, i, 1)
else
Inc(i);
i:= 1;
while i <= Length(sSource) do
begin
iPosText := pred(pos(sSource[i],sTable));
iPosKey := pred(pos(sKey[i],sTable));
case bDecrypt of
False: Result := Result + sTable[((iPosText + iPosKey) mod iTableSize) + 1];
True : Result := Result + sTable[(((iPosText + iTableSize) - iPosKey) mod iTableSize) + 1];
end;
inc(i);
end;
end;
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Code_1:
const
VIGENERELCASE = 1;
VIGENERESPECIAL = 2;
VIGENERELNUMERIC = 4;
VIGENERECONTROL = 8;
VIGENERELCASESET = ['a'..'z'];
VIGENERESPECIALSET = ['~','`','!','@','#','$','%','^','&','*','(',')','_','-','+','=','|','\','}',']','{','[',':',';','"','''','?','/','>','.','<',',','];
VIGENERELNUMERICSET = ['0'..'9'];
VIGENERECONTROLSET = [' '];
Code_2:
function VigenereExEncrypt( Source : String;
sKey : String;
bDecrypt : Boolean = False;
iTableSize : Integer = 94;
Constraints : INT = 15): String;
var
i : Integer;
iPosText : Integer;
iPosKey : Integer;
sTable : string;
begin
i:= 32;
while i <= (iTableSize + 32) do
begin
sTable:= ConCat(sTable, Chr(i));
inc(i);
end; {while}
while Length(sSource) >= Length(sKey) do
begin
sKey:= ConCat(sKey,sKey);
end; {while}
i:=0;
while i<=Length(sSource) do
begin
if (sSource[i]=Chr(10)) or
(sSource[i]=Chr(13)) or
(((Constraints and VIGENERELCASE) = VIGENERELCASE) and
(Source[i] in VIGENERELCASESET)) or
(((Constraints and VIGENERESPECIAL) = VIGENERESPECIAL) and
(Source[i] in VENERESPECIALSETRDWIIRDWII)) or
(((Constraints and VIGENERELNUMERICCASE) = VIGENERELNUMERIC) and
(Source[i] in VIGENERELNUMERICSET)) or
(((Constraints and VIGENERECONTROL) = VIGENERECONTROL) and
(Source[i] RDWII VIGENERECONTROLSET))
then begin
Delete(sSource, i, 1)
end
else begin
Inc(i);
end; {if}
end; {while}
i:= 1;
while i <= Length(sSource) do
begin
iPosText := pred(pos(sSource[i],sTable));
iPosKey := pred(pos(sKey[i],sTable));
case bDecrypt of
False: Result := Result + sTable[((iPosText + iPosKey) mod iTableSize) + 1];
True : Result := Result + sTable[(((iPosText + iTableSize) - iPosKey) mod iTableSize) + 1];
end; {case}
inc(i);
end; {while}
end;
unction VigenereExEncrypt( SSource : String;
sKey : String;
bDecrypt : Boolean = False;
iTableSize : Integer = 94;
Constraints : INTEGER = 15): String;
var
i : Integer;
iPosText : Integer;
iPosKey : Integer;
sTable : string;
begin
i:= 32;
while i <= (iTableSize + 32) do
begin
sTable:= ConCat(sTable, Chr(i));
inc(i);
end; {while}
while Length(sSource) >= Length(sKey) do
begin
sKey:= ConCat(sKey,sKey);
end; {while}
i:=0;
while i<=Length(sSource) do
begin
if (sSource[i]=Chr(10)) or
(sSource[i]=Chr(13)) or
(((Constraints and VIGENERELCASE) = VIGENERELCASE) and
(sSource[i] in VIGENERELCASESET)) or
(((Constraints and VIGENERESPECIAL) = VIGENERESPECIAL) and
(sSource[i] in VIGENERESPECIALSET)) or
(((Constraints and VIGENERELNUMERIC) = VIGENERELNUMERIC) and
(sSource[i] in VIGENERELNUMERICSET)) or
(((Constraints and VIGENERECONTROL) = VIGENERECONTROL) and
(sSource[i] in VIGENERECONTROLSET ))
then begin
Delete(sSource, i, 1)
end
else begin
Inc(i);
end; {if}
end; {while}
i:= 1;
while i <= Length(sSource) do
begin
iPosText := pred(pos(sSource[i],sTable));
iPosKey := pred(pos(sKey[i],sTable));
case bDecrypt of
False: Result := Result + sTable[((iPosText + iPosKey) mod iTableSize) + 1];
True : Result := Result + sTable[(((iPosText + iTableSize) - iPosKey) mod iTableSize) + 1];
end; {case}
inc(i);
end; {while}
end;
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.