Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,55 +0,0 @@
|
|||
WITH Ada.Text_IO, Ada.Characters.Handling;
|
||||
USE Ada.Text_IO, Ada.Characters.Handling;
|
||||
|
||||
PROCEDURE Main IS
|
||||
SUBTYPE Alpha IS Character RANGE 'A' .. 'Z';
|
||||
TYPE Ring IS MOD (Alpha'Range_length);
|
||||
TYPE Seq IS ARRAY (Integer RANGE <>) OF Ring;
|
||||
|
||||
FUNCTION "+" (S, Key : Seq) RETURN Seq IS
|
||||
R : Seq (S'Range);
|
||||
BEGIN
|
||||
FOR I IN R'Range LOOP
|
||||
R (I) := S (I) + Key (Key'First + (I - R'First) MOD Key'Length);
|
||||
END LOOP;
|
||||
RETURN R;
|
||||
END "+";
|
||||
|
||||
FUNCTION "-" (S : Seq) RETURN Seq IS
|
||||
R : Seq (S'Range);
|
||||
BEGIN
|
||||
FOR I IN R'Range LOOP
|
||||
R (I) := - S (I);
|
||||
END LOOP;
|
||||
RETURN R;
|
||||
END "-";
|
||||
|
||||
FUNCTION To_Seq (S : String) RETURN Seq IS
|
||||
R : Seq (S'Range);
|
||||
I : Integer := R'First;
|
||||
BEGIN
|
||||
FOR C OF To_Upper (S) LOOP
|
||||
IF C IN Alpha THEN
|
||||
R (I) := Ring'Mod (Alpha'Pos (C) - Alpha'Pos (Alpha'First));
|
||||
I := I + 1;
|
||||
END IF;
|
||||
END LOOP;
|
||||
RETURN R (R'First .. I - 1);
|
||||
END To_Seq;
|
||||
|
||||
FUNCTION To_String (S : Seq ) RETURN String IS
|
||||
R : String (S'Range);
|
||||
BEGIN
|
||||
FOR I IN R'Range LOOP
|
||||
R (I) := Alpha'Val ( Integer (S (I)) + Alpha'Pos (Alpha'First));
|
||||
END LOOP;
|
||||
RETURN R;
|
||||
END To_String;
|
||||
|
||||
Input : Seq := To_Seq (Get_Line);
|
||||
Key : Seq := To_Seq (Get_Line);
|
||||
Crypt : Seq := Input + Key;
|
||||
BEGIN
|
||||
Put_Line ("Encrypted: " & To_String (Crypt));
|
||||
Put_Line ("Decrypted: " & To_String (Crypt + (-Key)));
|
||||
END Main;
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
Letters: append `A`..`Z` `a`..`z`
|
||||
Letters: (@'A'..'Z') ++ (@'a'..'z')
|
||||
encrypt: function [msg, key][
|
||||
pos: 0
|
||||
result: new ""
|
||||
result: ""
|
||||
loop msg 'c ->
|
||||
if in? c Letters [
|
||||
'result ++ to :char (((to :integer key\[pos]) + to :integer upper c) % 26) + to :integer `A`
|
||||
'result ++ to :char (((to :integer key\[pos]) + to :integer upper c) % 26) + to :integer 'A'
|
||||
pos: (pos + 1) % size key
|
||||
]
|
||||
return result
|
||||
|
|
@ -12,9 +12,9 @@ encrypt: function [msg, key][
|
|||
|
||||
decrypt: function [msg, key][
|
||||
pos: 0
|
||||
result: new ""
|
||||
result: ""
|
||||
loop msg 'c [
|
||||
'result ++ to :char ((26 + (to :integer c) - to :integer key\[pos]) % 26) + to :integer `A`
|
||||
'result ++ to :char ((26 + (to :integer c) - to :integer key\[pos]) % 26) + to :integer 'A'
|
||||
pos: (pos + 1) % size key
|
||||
]
|
||||
return result
|
||||
|
|
|
|||
|
|
@ -1,14 +1,10 @@
|
|||
func$ encr txt$ pw$ d .
|
||||
txt$[] = strchars txt$
|
||||
for c$ in strchars pw$
|
||||
pw[] &= strcode c$ - 65
|
||||
.
|
||||
for c$ in strchars pw$ : pw[] &= strcode c$ - 65
|
||||
for c$ in txt$[]
|
||||
c = strcode c$
|
||||
if c >= 97
|
||||
c -= 32
|
||||
.
|
||||
if c >= 65 and c <= 97
|
||||
if c >= 97 : c -= 32
|
||||
if c >= 65 and c <= 90
|
||||
pwi = (pwi + 1) mod1 len pw[]
|
||||
c = (c - 65 + d * pw[pwi]) mod 26 + 65
|
||||
r$ &= strchar c
|
||||
|
|
|
|||
|
|
@ -29,18 +29,18 @@ class VCipher
|
|||
}
|
||||
}
|
||||
|
||||
public program()
|
||||
public Program()
|
||||
{
|
||||
var v := new VCipher();
|
||||
|
||||
var s0 := "Beware the Jabberwock, my son! The jaws that bite, the claws that catch!";
|
||||
var pw := "VIGENERECIPHER";
|
||||
|
||||
console.printLine(s0,newLineConstant,pw,newLineConstant);
|
||||
Console.printLine(s0,NewLineConstant,pw,NewLineConstant);
|
||||
var s1 := v.encrypt(s0, pw, 1);
|
||||
console.printLine("Encrypted:",s1);
|
||||
Console.printLine("Encrypted:",s1);
|
||||
s1 := v.encrypt(s1, "VIGENERECIPHER", -1);
|
||||
console.printLine("Decrypted:",s1);
|
||||
console.printLine("Press any key to continue..");
|
||||
console.readChar()
|
||||
Console.printLine("Decrypted:",s1);
|
||||
Console.printLine("Press any key to continue..");
|
||||
Console.readChar()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,85 +0,0 @@
|
|||
# Author: D. Cudnohufsky
|
||||
function Get-VigenereCipher
|
||||
{
|
||||
Param
|
||||
(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string] $Text,
|
||||
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string] $Key,
|
||||
|
||||
[switch] $Decode
|
||||
)
|
||||
|
||||
begin
|
||||
{
|
||||
$map = [char]'A'..[char]'Z'
|
||||
}
|
||||
|
||||
process
|
||||
{
|
||||
$Key = $Key -replace '[^a-zA-Z]',''
|
||||
$Text = $Text -replace '[^a-zA-Z]',''
|
||||
|
||||
$keyChars = $Key.toUpper().ToCharArray()
|
||||
$Chars = $Text.toUpper().ToCharArray()
|
||||
|
||||
function encode
|
||||
{
|
||||
|
||||
param
|
||||
(
|
||||
$Char,
|
||||
$keyChar,
|
||||
$Alpha = [char]'A'..[char]'Z'
|
||||
)
|
||||
|
||||
$charIndex = $Alpha.IndexOf([int]$Char)
|
||||
$keyIndex = $Alpha.IndexOf([int]$keyChar)
|
||||
$NewIndex = ($charIndex + $KeyIndex) - $Alpha.Length
|
||||
$Alpha[$NewIndex]
|
||||
|
||||
}
|
||||
|
||||
function decode
|
||||
{
|
||||
|
||||
param
|
||||
(
|
||||
$Char,
|
||||
$keyChar,
|
||||
$Alpha = [char]'A'..[char]'Z'
|
||||
)
|
||||
|
||||
$charIndex = $Alpha.IndexOf([int]$Char)
|
||||
$keyIndex = $Alpha.IndexOf([int]$keyChar)
|
||||
$int = $charIndex - $keyIndex
|
||||
if ($int -lt 0) { $NewIndex = $int + $Alpha.Length }
|
||||
else { $NewIndex = $int }
|
||||
$Alpha[$NewIndex]
|
||||
}
|
||||
|
||||
while ( $keyChars.Length -lt $Chars.Length )
|
||||
{
|
||||
$keyChars = $keyChars + $keyChars
|
||||
}
|
||||
|
||||
for ( $i = 0; $i -lt $Chars.Length; $i++ )
|
||||
{
|
||||
|
||||
if ( [int]$Chars[$i] -in $map -and [int]$keyChars[$i] -in $map )
|
||||
{
|
||||
if ($Decode) {$Chars[$i] = decode $Chars[$i] $keyChars[$i] $map}
|
||||
else {$Chars[$i] = encode $Chars[$i] $keyChars[$i] $map}
|
||||
|
||||
$Chars[$i] = [char]$Chars[$i]
|
||||
[string]$OutText += $Chars[$i]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$OutText
|
||||
$OutText = $null
|
||||
}
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
Function Encrypt(text,key)
|
||||
text = OnlyCaps(text)
|
||||
key = OnlyCaps(key)
|
||||
j = 1
|
||||
For i = 1 To Len(text)
|
||||
ms = Mid(text,i,1)
|
||||
m = Asc(ms) - Asc("A")
|
||||
ks = Mid(key,j,1)
|
||||
k = Asc(ks) - Asc("A")
|
||||
j = (j Mod Len(key)) + 1
|
||||
c = (m + k) Mod 26
|
||||
c = Chr(Asc("A")+c)
|
||||
Encrypt = Encrypt & c
|
||||
Next
|
||||
End Function
|
||||
|
||||
Function Decrypt(text,key)
|
||||
key = OnlyCaps(key)
|
||||
j = 1
|
||||
For i = 1 To Len(text)
|
||||
ms = Mid(text,i,1)
|
||||
m = Asc(ms) - Asc("A")
|
||||
ks = Mid(key,j,1)
|
||||
k = Asc(ks) - Asc("A")
|
||||
j = (j Mod Len(key)) + 1
|
||||
c = (m - k + 26) Mod 26
|
||||
c = Chr(Asc("A")+c)
|
||||
Decrypt = Decrypt & c
|
||||
Next
|
||||
End Function
|
||||
|
||||
Function OnlyCaps(s)
|
||||
For i = 1 To Len(s)
|
||||
char = UCase(Mid(s,i,1))
|
||||
If Asc(char) >= 65 And Asc(char) <= 90 Then
|
||||
OnlyCaps = OnlyCaps & char
|
||||
End If
|
||||
Next
|
||||
End Function
|
||||
|
||||
'testing the functions
|
||||
orig_text = "Beware the Jabberwock, my son! The jaws that bite, the claws that catch!"
|
||||
orig_key = "vigenerecipher"
|
||||
WScript.StdOut.WriteLine "Original: " & orig_text
|
||||
WScript.StdOut.WriteLine "Key: " & orig_key
|
||||
WScript.StdOut.WriteLine "Encrypted: " & Encrypt(orig_text,orig_key)
|
||||
WScript.StdOut.WriteLine "Decrypted: " & Decrypt(Encrypt(orig_text,orig_key),orig_key)
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
'vigenere cypher
|
||||
option explicit
|
||||
const asca =65 'ascii(a)
|
||||
|
||||
function filter(s)
|
||||
with new regexp
|
||||
.pattern="[^A-Z]"
|
||||
.global=1
|
||||
filter=.replace(ucase(s),"")
|
||||
end with
|
||||
end function
|
||||
|
||||
function vigenere (s,k,sign)
|
||||
dim s1,i,a,b
|
||||
for i=0 to len(s)-1
|
||||
a=asc(mid(s,i+1,1))-asca
|
||||
b=sign * (asc(mid(k,(i mod len(k))+1,1))-asca)
|
||||
s1=s1 & chr(((a+b+26) mod 26) +asca)
|
||||
next
|
||||
vigenere=s1
|
||||
end function
|
||||
|
||||
function encrypt(s,k): encrypt=vigenere(s,k,1) :end function
|
||||
function decrypt(s,k): decrypt=vigenere(s,k,-1) :end function
|
||||
|
||||
'test--------------------------
|
||||
dim plaintext,filtered,key,encoded
|
||||
key="VIGENERECYPHER"
|
||||
plaintext = "Beware the Jabberwock, my son! The jaws that bite, the claws that catch!"
|
||||
filtered= filter(plaintext)
|
||||
wscript.echo filtered
|
||||
encoded=encrypt(filtered,key)
|
||||
wscript.echo encoded
|
||||
wscript.echo decrypt(encoded,key)
|
||||
Loading…
Add table
Add a link
Reference in a new issue