Jump to content

trying to encrypt a web page


 Share

Recommended Posts

I want to change all the text in a web page according to a given encryption algorithm. I couldn't find a _IEBodyWriteText function in my version of AutoIt (v3.2.2.0), so I built one based on _IEBodyReadText and _IEBodyWriteHTML. But instead of just replacing the text with its encrypted equivalent, the script makes a page that's just the encrypted text, without any links, graphics, etc. This isn't what I want; I want to preserve the formatting of the page and just change the words. Here's the code:

#include <ie.au3>
#include <string.au3>

$title="encryptPage"
$url=inputbox($title,"Enter URL:")

$page=_iecreate($url)
$plaintext=_IEBodyReadtext($page)
$ciphertext=encrypt($plaintext)
_IEBodyWritetext($page,$ciphertext)

func encrypt($text)
    $len=stringlen($text)
    $newtext=""
    for $c=1 to $len
        $char=stringmid($text,$c,1)
        $new=cipher($char)
        $newtext=$newtext&$new
    Next
    return $newtext
EndFunc

func cipher($char)
    if stringisalpha($char) Then
        $num=asc($char)
        $newchar=chr($num+1)
        return $newchar
    Else
        return($char)
    EndIf
EndFunc

Func _IEBodyWriteText(ByRef $o_object, $s_text)
    If Not IsObj($o_object) Then
        __IEErrorNotify("Error", "_IEBodyWriteHTML", "$_IEStatus_InvalidDataType")
        SetError($_IEStatus_InvalidDataType, 1)
        Return 0
    EndIf
;
    $o_object.document.body.innerText = $s_text
    Local $oTemp = $o_object.document
    _IELoadWait($oTemp)
    SetError(@error)
    Return -1
EndFunc

For various IT-security related reasons, I don't have administrative rights to install the newest AutoIt release, so a solution like "just use the _IEBodyWriteText function in the latest release" isn't feasible. However, a link to a UDF library that has a _IEBodyWriteText function will help.

Link to comment
Share on other sites

When you say you want to encrypt the text, what exactly do you mean? Do you mean text in certain regions or all text including labels and buttons etc.?

Something like this comes to mind:

$oBody = _IETagnameGetCollection($oIE, "body", 0)
$oElements = _IETagnameAllGetCollection($oBody)
For $oElement in $oElements
    $sText = _IEPropertyGet($oElement, "innertext")
    _IEPropertySet($oElement, "innertext", encrypt($sText))
Next

Not tested. Could break things.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...