Seite 1 von 1

Blockchifre

Verfasst: 26.02.2008 01:06
von R4z0r1989
So Leute ich hab mal eine Frage:

Ich hab mir selber ein Blockchifre mit 128 bit gemacht,
ob es sicher ist sei dahin gestellt,
will damit ja nur kleine Kinder abschrecken, :twisted:
ne aber mal Spass bei seite.

Also, eine Datei wird selten genau durch 16 Teilbar sein und da ich ja in meiner Verschlüsselung immer 16 byte rausbekomm ist die Frage wie ich die letzten 1-15 Bytes Verschlüssle ohne sie möglicher weiße nach dem entschlüsseln zu beschädigen?

Mir gehn die Ideen aus ^^

Und für intresierte hier der Algo:

Verschlüsseln:

Code: Alles auswählen

Procedure Quersumme(zahl.q)
  Protected Result.l
 
  If zahl < 0 : zahl * -1 : EndIf
  While zahl
    Result + zahl % 10
    zahl / 10
  Wend
 
  ProcedureReturn Result
EndProcedure

Procedure.s FriZaV(text$,pawo$)

Dim text.w(5,5)
Dim pawo.w(5,5)

For y = 1 To 4
  For x = 1 To 4
    z = y + ((x-1) * 4)
    text(x,y) = Asc(Right(Left(text$,z),1))
    pawo(x,y) = Asc(Right(Left(pawo$,z),1))
  Next x
Next y

For y = 1 To 4
  For x = 1 To 4
    hex$ = RSet(Hex(text(x,y)), 2, "0")
    taus0$ = Left(hex$,1)
    taus1$ = Right(hex$,1)
    hex$ = taus1$ + taus0$
    text(x,y) = Hex2Dec(hex$)
  Next x
Next y

For y = 1 To 4
  For x = 1 To 4
    byte = text(x,y)
    byte = byte + pawo(x,y)
    If byte > 255
      byte - 255
    EndIf
    text(x,y) = byte
  Next x
Next y

For y = 1 To 4
  For x = 1 To 4
    hex$ = RSet(Hex(text(x,y)), 2, "0")
    taus0$ = Left(hex$,1)
    taus1$ = Right(hex$,1)
    hex$ = taus1$ + taus0$
    text(x,y) = Hex2Dec(hex$)
  Next x
Next y

For z = 1 To 15

text(1,5) = text(1,1)
text(1,1) = text(1,2)
text(1,2) = text(1,3)
text(1,3) = text(1,4)
text(1,4) = text(1,5)

text(2,5) = text(2,1)
text(2,1) = text(2,3)
text(2,3) = text(2,5)
text(2,5) = text(2,2)
text(2,2) = text(2,4)
text(2,4) = text(2,5)

text(3,5) = text(3,1)
text(3,1) = text(3,4)
text(3,4) = text(3,3)
text(3,3) = text(3,2)
text(3,2) = text(3,5)

text(1,5) = text(1,1)
text(2,5) = text(2,1)
text(3,5) = text(3,1)
text(4,5) = text(4,1)

text(1,1) = text(1,3)
text(2,1) = text(2,3)
text(3,1) = text(3,3)
text(4,1) = text(4,3)

text(1,3) = text(1,5)
text(2,3) = text(2,5)
text(3,3) = text(3,5)
text(4,3) = text(4,5)

text(1,5) = text(1,2)
text(2,5) = text(2,2)
text(3,5) = text(3,2)
text(4,5) = text(4,2)

text(1,2) = text(1,4)
text(2,2) = text(2,4)
text(3,2) = text(3,4)
text(4,2) = text(4,4)

text(1,4) = text(1,5)
text(2,4) = text(2,5)
text(3,4) = text(3,5)
text(4,4) = text(4,5)

quer = 0

For x = 1 To 16
  quer = quer + Asc(Right(Left(pawo$,x),1))
Next x
Repeat
  quer = Quersumme(quer)
Until quer < 10

If quer <= 4
  line = 1
ElseIf quer <= 8
  line = 2
  quer = quer - 4
Else
  line = 3
  quer = quer - 8
EndIf

text(5,1) = text(quer,line)
text(quer,line) = text(1,1)
text(1,1) = text(5,1)

quer = Quersumme(quer*2)

If quer <= 4
  line = 1
ElseIf quer <= 8
  line = 2
  quer = quer - 4
Else
  line = 3
  quer = quer - 8
EndIf

text(5,1) = text(quer,line)
text(quer,line) = text(1,1)
text(1,1) = text(5,1)

Next z

For y = 1 To 4
  For x = 1 To 4
    byte = text(x,y)
    byte = byte + pawo(x,y)
    If byte > 255
      byte - 255
    EndIf
    text(x,y) = byte
  Next x
Next y

For y = 1 To 4
  For x = 1 To 4
    hex$ = RSet(Hex(text(x,y)), 2, "0")
    taus0$ = Left(hex$,1)
    taus1$ = Right(hex$,1)
    hex$ = taus1$ + taus0$
    text(x,y) = Hex2Dec(hex$)
  Next x
Next y

For x = 1 To 4
  For y = 1 To 4
    chif1$ = chif1$ + Chr(text(x,y))
  Next y
Next x

ProcedureReturn chif1$

EndProcedure

Debug FriZaV("Goldregenpfeifer","abcdefghijklmnop")
Entschlüssenln:

Code: Alles auswählen

Procedure Quersumme(zahl.q)
  Protected Result.l
 
  If zahl < 0 : zahl * -1 : EndIf
  While zahl
    Result + zahl % 10
    zahl / 10
  Wend
 
  ProcedureReturn Result
EndProcedure

Procedure.s FriZaE(text$,pawo$)

Dim text.w(5,5)
Dim pawo.w(5,5)

For y = 1 To 4
  For x = 1 To 4
    z = y + ((x-1) * 4)
    text(x,y) = Asc(Right(Left(text$,z),1))
    pawo(x,y) = Asc(Right(Left(pawo$,z),1))
  Next x
Next y

For y = 1 To 4
  For x = 1 To 4
    hex$ = RSet(Hex(text(x,y)), 2, "0")
    taus0$ = Left(hex$,1)
    taus1$ = Right(hex$,1)
    hex$ = taus1$ + taus0$
    text(x,y) = Hex2Dec(hex$)
  Next x
Next y

For y = 1 To 4
  For x = 1 To 4
    byte = text(x,y)
    byte = byte - pawo(x,y)
    If byte < 0
      byte + 255
    EndIf
    text(x,y) = byte
  Next x
Next y

For z = 1 To 15

quer = 0

For x = 1 To 16
  quer = quer + Asc(Right(Left(pawo$,x),1))
Next x
Repeat
  quer = Quersumme(quer)
Until quer < 10

quer2 = Quersumme(quer*2)

If quer <= 4
  line = 1
ElseIf quer <= 8
  line = 2
  quer = quer - 4
Else
  line = 3
  quer = quer - 8
EndIf

If quer2 <= 4
  line2 = 1
ElseIf quer2 <= 8
  line2 = 2
  quer2 = quer2 - 4
Else
  line2 = 3
  quer2 = quer2 - 8
EndIf

text(5,1) = text(1,1)
text(1,1) = text(quer2,line2)
text(quer2,line2) = text(5,1)

text(5,1) = text(1,1)
text(1,1) = text(quer,line)
text(quer,line) = text(5,1)

text(4,5) = text(4,2)
text(3,5) = text(3,2)
text(2,5) = text(2,2)
text(1,5) = text(1,2)

text(4,2) = text(4,4)
text(3,2) = text(3,4)
text(2,2) = text(2,4)
text(1,2) = text(1,4)

text(4,4) = text(4,5)
text(3,4) = text(3,5)
text(2,4) = text(2,5)
text(1,4) = text(1,5)

text(4,5) = text(4,1)
text(3,5) = text(3,1)
text(2,5) = text(2,1)
text(1,5) = text(1,1)

text(4,1) = text(4,3)
text(3,1) = text(3,3)
text(2,1) = text(2,3)
text(1,1) = text(1,3)

text(4,3) = text(4,5)
text(3,3) = text(3,5)
text(2,3) = text(2,5)
text(1,3) = text(1,5)

text(3,5) = text(3,1)
text(3,1) = text(3,2)
text(3,2) = text(3,3)
text(3,3) = text(3,4)
text(3,4) = text(3,5)

text(2,5) = text(2,4)
text(2,4) = text(2,2)
text(2,2) = text(2,5)
text(2,5) = text(2,3)
text(2,3) = text(2,1)
text(2,1) = text(2,5)

text(1,5) = text(1,4)
text(1,4) = text(1,3)
text(1,3) = text(1,2)
text(1,2) = text(1,1)
text(1,1) = text(1,5)

Next z

For y = 1 To 4
  For x = 1 To 4
    hex$ = RSet(Hex(text(x,y)), 2, "0")
    taus0$ = Left(hex$,1)
    taus1$ = Right(hex$,1)
    hex$ = taus1$ + taus0$
    text(x,y) = Hex2Dec(hex$)
  Next x
Next y

For y = 1 To 4
  For x = 1 To 4
    byte = text(x,y)
    byte = byte - pawo(x,y)
    If byte < 0
      byte + 255
    EndIf
    text(x,y) = byte
  Next x
Next y

For y = 1 To 4
  For x = 1 To 4
    hex$ = RSet(Hex(text(x,y)), 2, "0")
    taus0$ = Left(hex$,1)
    taus1$ = Right(hex$,1)
    hex$ = taus1$ + taus0$
    text(x,y) = Hex2Dec(hex$)
  Next x
Next y

For x = 1 To 4
  For y = 1 To 4
    chif1$ = chif1$ + Chr(text(x,y))
  Next y
Next x

ProcedureReturn chif1$

EndProcedure

Debug FriZaE("ámÏ

Verfasst: 26.02.2008 10:10
von NicTheQuick
Hab mir deinen Code jetzt nicht angeschaut, aber ich die gängigste Idee dein
16-Byte-Problem zu lösen ist die letzten übrig bleibenden Bits mit einer 1 und
den Rest mit Null aufzufüllen. Sollte die Bufferlänge durch 16 teilbar sein,
hängst du dementsprechend nochmal 16 Bytes mit 10000... an. Wenn du dir
aber sowieso merkst, wie viel Byte der zu verschlüsselnde Buffer hat, kannst
du auch einfach Zufallswerte zum Auffüllen verwenden und die Länge des
Buffers als Long oder Quad in die ersten 4 Bytes packen und mit
verschlüsseln.

hui

Verfasst: 26.02.2008 17:56
von R4z0r1989
danke die idee is gut und ich ned drauf gekommen ^^
bin ich schlecht ^^