Césarovou šifrou - Visual Basic Vyřešeno
Napsal: 24 dub 2012 13:05
Zdravím, potřeboval bych pomoc s Césarovou šifrou ve VB.
České diskuzní fórum o počítačích
https://pc-help.cnews.cz/
Kód: Vybrat vše
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
D E F G H I J K L M N O P Q R S T U V W X Y Z A B C
Kód: Vybrat vše
Text [ ]
Klíč [ ]
[Zašifrovat] [Dešifrovat]
Výsledek [ ]
Kód: Vybrat vše
vysledek=text
while (posun>0)
for i=1 to len(vysledek)
znak=asc(mid(vysledek,i,1))
if ((znak>=65 and znak<=90) or (znak>=97 and znak<=122)) then
if (znak>90) then znak=znak-32
znak=znak+(posun mod 10)
if (znak>90) then znak=znak-26
end if
mid(vysledek,i)=chr(znak)
next i
posun=posun/10
wend
Kód: Vybrat vše
znak=znak-(posun mod 10)
if (znak<65) then znak=znak+26
Kód: Vybrat vše
Dim posun As Long
posun = UCase(text2.Text)
Kód: Vybrat vše
znak = Chr(Asc(znak) + 3)
Šifrované slovo:
Kolik
Šifra: 12
Zašifrované slovo: Lqmkl
Kód: Vybrat vše
for i=32 to 255
print chr$(i);" ";
if (i mod 16 = 15) then print
next i
Kód: Vybrat vše
Function EncryptDecrypt(ByVal text1 As String, ByVal key As String, ByVal isEncrypt As Boolean) As String
Dim char1 As String 'primo carattere del testo da cifrare/decifrare
Dim char2 As String 'carattere cifrato/decifrato
Dim cKey As Byte 'cifra chiave
'lunghezza stringa da cifrare/decifrare
Dim strLength As Integer
Dim Result As String = "" 'risultato finale
Dim j As Integer = -1
If text1 <> "" And IsNumeric(key) Then
strLength = text1.Length
For i As Integer = 0 To strLength - 1
char1 = text1.Substring(i, 1) 'estrae carattere
If j < key.Length - 1 Then
j = j + 1
Else
j = 0
End If
cKey = Val(key.Substring(j, 1))
If isEncrypt Then 'se voglio cifrare il testo
If (Asc(char1) + cKey) > 255 Then
char2 = Chr(Asc(char1) + cKey - 255)
Else
char2 = Chr(Asc(char1) + cKey)
End If
Else
If (Asc(char1) - cKey) < 1 Then
char2 = Chr(Asc(char1) - cKey + 255)
Else
char2 = Chr(Asc(char1) - cKey)
End If
End If
Result &= char2
Next
Else
MsgBox("Enter text or key!")
End If
Return Result
End Function