0

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
Domen Lisjak
  • 45
  • 1
  • 7
  • What is your question? If there are errors or there is an outcome that you do not expect then please show that. – Jim K Dec 08 '15 at 22:07
  • It looks like this line may be causing an infinite loop: `dolzina = dolzina +1`. However I do not really know. Please see if you can simplify the question: http://stackoverflow.com/help/mcve. – Jim K Dec 08 '15 at 22:27
  • Possible duplicate of [Function not allowed within a procedure](http://stackoverflow.com/questions/34162394/function-not-allowed-within-a-procedure) – EEM Dec 09 '15 at 17:20
  • @EEM: I am not sure it should be considered a duplicate because the poster fixed the bug from that post. Apparently at least one more problem with the code remains. See http://meta.stackexchange.com/questions/98801/is-it-better-to-ask-one-complex-question-or-a-bunch-of-tiny-questions?lq=1 – Jim K Dec 10 '15 at 05:09

0 Answers0