I have an assignment to make a macro in LibreOffice that I have to code a text using XOR operations. the instructions are following.
izracunajHash function (password zacetni_hash) - This function will implement a hash function that will calculate the user's password from the initial seed for the pseudo-random number generator. To receive functions are set following additional requirements:
Variable zacetni_hash to the setpoint 17520
The function of taking the characters from the first character to the last Walk through the characters need to implement the loop for
function encode (string) - output of the function will be encoded / decoded input string. Assume that the random number generator are set to the correct value. Encode only the characters whose ascii value is greater than 31. For admission functions are set following additional requirements:
The function of taking the characters from the last character to the first
Walk through the characters you must be implemented with the Do While Loop
sub kodiraj_besedilo (seed) - This subroutine ensures that encode all the paragraphs in plain text. Also in this subprogram the initialisation of the random value
kodiraj_UI sub - this subroutine contains a user interface for your macro is basically the main program. You will require a password for encryption and call routines sooner Headquarters
I have written to this point:
REM ***** BASIC *****
function izracunajHash(geslo, zacetni_hash)
zacetni_hash = 17520
hash = zacetni_hash
mask = &H00FFFFFF
dolzina = len(geslo)
If dolzina > 0 Then
for f=1 to dolzina step +1
podniz = mid(geslo,dolzina,1)
char = Asc("podniz")
hash = 33*hash + char
hash = hash AND mask
dolzina = dolzina +1
hash = hash AND &H00FFFFFF
next f
End If
izracunajHash = hash
End function
function kodiraj(niz)
y = 1
if Len(niz) > 0 Then
x = Len(niz)
Do While y > (x+1)
sign = Mid(niz, y, 1)
z1 = Asc(sign)
if z1 > 31 Then
z2 = (CInt(rnd()*31))
z1 = z1 XOR z2
z1 = Chr(z1)
Mid(niz,y,1,z1)
End If
y = y + 1
Loop
End If
kodiraj = niz
End function
Sub kodiraj_besedilo(seme)
Randomize(seme)
oParEnum = ThisComponent.Text.createEnumeration()
Do While oParEnum.hasMoreElements()
oPar = oParEnum.nextElement()
If oPar.supportsService("com.sun.star.text.Paragraph") Then
oPar.String = kodiraj(oPar.String)
End If
Loop
End Sub
Sub kodiraj_UI
geslo = InputBox("Vnesi niz:", "Geslo", "E1087385")
hash = izracunajHash(geslo, 17520)
kodiraj_besedilo(hash)
msgBox("Končaj")
End Sub