Cäsar-Verschlüsselung mit Zahlen
#11
Hallo,

noch eine Variante mit VBA, sowohl für Zahlen als auch Unicode:

Code:
Const key As Integer = 5

Sub Start()
For i = 2845 To 3456 Step 37
'i = 3030
    z = z + 1
    enc = fn_Caesar_enc(i)
    dec = fn_Caesar_dec(enc)
    Debug.Print i, enc, dec, VBA.StrConv(CStr(i), vbFromUnicode)
    Cells(z, 1) = i
    Cells(z, 2) = enc
    Cells(z, 3) = dec
    Cells(z, 4) = StrConv(CStr(i), vbFromUnicode)
    Cells(z, 5) = StrConv(CStr(enc), vbFromUnicode)
    Cells(z, 6) = StrConv(CStr(dec), vbFromUnicode)
Next i
End Sub

Function fn_Caesar_enc(ByVal i As Integer) As Integer
Dim ret As String

For j = 1 To 4
    ret = ret & (Mid(i, j, 1) + key) Mod 10
Next j

fn_Caesar_enc = ret
End Function

Function fn_Caesar_dec(ByVal enc As Integer) As Integer
Dim ret As String, z As Integer

For j = 1 To 4
    z = Mid(enc, j, 1) - key
    ret = ret & IIf(z >= 0, z, 10 + z)
Next j

fn_Caesar_dec = ret
End Function

mfg


Angehängte Dateien
.xlsm   Caesar 4-Stellen Unicode.xlsm (Größe: 17,63 KB / Downloads: 2)
Antworten Top


Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste