Jump to content

Password Protect Code


GoravG
 Share

Recommended Posts

Could you please add some description what your code is all about?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

The code...

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.10.0
 Author:         GoravG

#ce ----------------------------------------------------------------------------

Func _stringencrypt($i_encrypt, $s_encrypttext, $s_encryptpassword, $i_encryptlevel = 1)
    If $i_encrypt <> 0 AND $i_encrypt <> 1 Then
        SetError(1, 0, "")
    ElseIf $s_encrypttext = "" OR $s_encryptpassword = "" Then
        SetError(1, 0, "")
    Else
        If Number($i_encryptlevel) <= 0 OR Int($i_encryptlevel) <> $i_encryptlevel Then $i_encryptlevel = 1
        Local $v_encryptmodified
        Local $i_encryptcounth
        Local $i_encryptcountg
        Local $v_encryptswap
        Local $av_encryptbox[256][2]
        Local $i_encryptcounta
        Local $i_encryptcountb
        Local $i_encryptcountc
        Local $i_encryptcountd
        Local $i_encryptcounte
        Local $v_encryptcipher
        Local $v_encryptcipherby
        If $i_encrypt = 1 Then
            For $i_encryptcountf = 0 To $i_encryptlevel Step 1
                $i_encryptcountg = ""
                $i_encryptcounth = ""
                $v_encryptmodified = ""
                For $i_encryptcountg = 1 To StringLen($s_encrypttext)
                    If $i_encryptcounth = StringLen($s_encryptpassword) Then
                        $i_encryptcounth = 1
                    Else
                        $i_encryptcounth += 1
                    EndIf
                    $v_encryptmodified = $v_encryptmodified & Chr(BitXOR(Asc(StringMid($s_encrypttext, $i_encryptcountg, 1)), Asc(StringMid($s_encryptpassword, $i_encryptcounth, 1)), 255))
                Next
                $s_encrypttext = $v_encryptmodified
                $i_encryptcounta = ""
                $i_encryptcountb = 0
                $i_encryptcountc = ""
                $i_encryptcountd = ""
                $i_encryptcounte = ""
                $v_encryptcipherby = ""
                $v_encryptcipher = ""
                $v_encryptswap = ""
                $av_encryptbox = ""
                Local $av_encryptbox[256][2]
                For $i_encryptcounta = 0 To 255
                    $av_encryptbox[$i_encryptcounta][1] = Asc(StringMid($s_encryptpassword, Mod($i_encryptcounta, StringLen($s_encryptpassword)) + 1, 1))
                    $av_encryptbox[$i_encryptcounta][0] = $i_encryptcounta
                Next
                For $i_encryptcounta = 0 To 255
                    $i_encryptcountb = Mod(($i_encryptcountb + $av_encryptbox[$i_encryptcounta][0] + $av_encryptbox[$i_encryptcounta][1]), 256)
                    $v_encryptswap = $av_encryptbox[$i_encryptcounta][0]
                    $av_encryptbox[$i_encryptcounta][0] = $av_encryptbox[$i_encryptcountb][0]
                    $av_encryptbox[$i_encryptcountb][0] = $v_encryptswap
                Next
                For $i_encryptcounta = 1 To StringLen($s_encrypttext)
                    $i_encryptcountc = Mod(($i_encryptcountc + 1), 256)
                    $i_encryptcountd = Mod(($i_encryptcountd + $av_encryptbox[$i_encryptcountc][0]), 256)
                    $i_encryptcounte = $av_encryptbox[Mod(($av_encryptbox[$i_encryptcountc][0] + $av_encryptbox[$i_encryptcountd][0]), 256)][0]
                    $v_encryptcipherby = BitXOR(Asc(StringMid($s_encrypttext, $i_encryptcounta, 1)), $i_encryptcounte)
                    $v_encryptcipher &= Hex($v_encryptcipherby, 2)
                Next
                $s_encrypttext = $v_encryptcipher
            Next
        Else
            For $i_encryptcountf = 0 To $i_encryptlevel Step 1
                $i_encryptcountb = 0
                $i_encryptcountc = ""
                $i_encryptcountd = ""
                $i_encryptcounte = ""
                $v_encryptcipherby = ""
                $v_encryptcipher = ""
                $v_encryptswap = ""
                $av_encryptbox = ""
                Local $av_encryptbox[256][2]
                For $i_encryptcounta = 0 To 255
                    $av_encryptbox[$i_encryptcounta][1] = Asc(StringMid($s_encryptpassword, Mod($i_encryptcounta, StringLen($s_encryptpassword)) + 1, 1))
                    $av_encryptbox[$i_encryptcounta][0] = $i_encryptcounta
                Next
                For $i_encryptcounta = 0 To 255
                    $i_encryptcountb = Mod(($i_encryptcountb + $av_encryptbox[$i_encryptcounta][0] + $av_encryptbox[$i_encryptcounta][1]), 256)
                    $v_encryptswap = $av_encryptbox[$i_encryptcounta][0]
                    $av_encryptbox[$i_encryptcounta][0] = $av_encryptbox[$i_encryptcountb][0]
                    $av_encryptbox[$i_encryptcountb][0] = $v_encryptswap
                Next
                For $i_encryptcounta = 1 To StringLen($s_encrypttext) Step 2
                    $i_encryptcountc = Mod(($i_encryptcountc + 1), 256)
                    $i_encryptcountd = Mod(($i_encryptcountd + $av_encryptbox[$i_encryptcountc][0]), 256)
                    $i_encryptcounte = $av_encryptbox[Mod(($av_encryptbox[$i_encryptcountc][0] + $av_encryptbox[$i_encryptcountd][0]), 256)][0]
                    $v_encryptcipherby = BitXOR(Dec(StringMid($s_encrypttext, $i_encryptcounta, 2)), $i_encryptcounte)
                    $v_encryptcipher = $v_encryptcipher & Chr($v_encryptcipherby)
                Next
                $s_encrypttext = $v_encryptcipher
                $i_encryptcountg = ""
                $i_encryptcounth = ""
                $v_encryptmodified = ""
                For $i_encryptcountg = 1 To StringLen($s_encrypttext)
                    If $i_encryptcounth = StringLen($s_encryptpassword) Then
                        $i_encryptcounth = 1
                    Else
                        $i_encryptcounth += 1
                    EndIf
                    $v_encryptmodified &= Chr(BitXOR(Asc(StringMid($s_encrypttext, $i_encryptcountg, 1)), Asc(StringMid($s_encryptpassword, $i_encryptcounth, 1)), 255))
                Next
                $s_encrypttext = $v_encryptmodified
            Next
        EndIf
        Return $s_encrypttext
    EndIf
EndFunc

Global Const $mb_systemmodal = 4096
Global Const $hgdi_error = Ptr(-1)
Global Const $invalid_handle_value = Ptr(-1)
Global Const $kf_extended = 256
Global Const $kf_altdown = 8192
Global Const $kf_up = 32768
Global Const $llkhf_extended = BitShift($kf_extended, 8)
Global Const $llkhf_altdown = BitShift($kf_altdown, 8)
Global Const $llkhf_up = BitShift($kf_up, 8)
Global Const $load_library_as_datafile = 2
Global Const $tagrect = "struct;long Left;long Top;long Right;long Bottom;endstruct"
Global Const $taggdipstartupinput = "uint Version;ptr Callback;bool NoThread;bool NoCodecs"
Global Const $tagrebarbandinfo = "uint cbSize;uint fMask;uint fStyle;dword clrFore;dword clrBack;ptr lpText;uint cch;" & "int iImage;hwnd hwndChild;uint cxMinChild;uint cyMinChild;uint cx;handle hbmBack;uint wID;uint cyChild;uint cyMaxChild;" & "uint cyIntegral;uint cxIdeal;lparam lParam;uint cxHeader" & ((@OSVersion = "WIN_XP") ? "" : ";" & $tagrect & ";uint uChevronState")

Func _winapi_freelibrary($hmodule)
    Local $aresult = DllCall("kernel32.dll", "bool", "FreeLibrary", "handle", $hmodule)
    If @error Then Return SetError(@error, @extended, False)
    Return $aresult[0]
EndFunc

Func _winapi_getmodulehandle($smodulename)
    Local $smodulenametype = "wstr"
    If $smodulename = "" Then
        $smodulename = 0
        $smodulenametype = "ptr"
    EndIf
    Local $aresult = DllCall("kernel32.dll", "handle", "GetModuleHandleW", $smodulenametype, $smodulename)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aresult[0]
EndFunc

Func _winapi_loadimage($hinstance, $simage, $itype, $ixdesired, $iydesired, $iload)
    Local $aresult, $simagetype = "int"
    If IsString($simage) Then $simagetype = "wstr"
    $aresult = DllCall("user32.dll", "handle", "LoadImageW", "handle", $hinstance, $simagetype, $simage, "uint", $itype, "int", $ixdesired, "int", $iydesired, "uint", $iload)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aresult[0]
EndFunc

Func _winapi_loadlibraryex($sfilename, $iflags = 0)
    Local $aresult = DllCall("kernel32.dll", "handle", "LoadLibraryExW", "wstr", $sfilename, "ptr", 0, "dword", $iflags)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aresult[0]
EndFunc

Global Const $tagosversioninfo = "struct;dword OSVersionInfoSize;dword MajorVersion;dword MinorVersion;dword BuildNumber;dword PlatformId;wchar CSDVersion[128];endstruct"
Global Const $__winver = __winver()

Func __winver()
    Local $tosvi = DllStructCreate($tagosversioninfo)
    DllStructSetData($tosvi, 1, DllStructGetSize($tosvi))
    Local $ret = DllCall("kernel32.dll", "bool", "GetVersionExW", "struct*", $tosvi)
    If @error OR NOT $ret[0] Then Return SetError(@error, @extended, 0)
    Return BitOR(BitShift(DllStructGetData($tosvi, 2), -8), DllStructGetData($tosvi, 3))
EndFunc

Global $ghgdipdll = 0
Global $gigdipref = 0
Global $gigdiptoken = 0
Global $gbgdip_v1_0 = True

Func _gdiplus_startup($sgdipdll = Default)
    $gigdipref += 1
    If $gigdipref > 1 Then Return True
    If $sgdipdll = Default Then
        If @OSBuild > 4999 AND @OSBuild < 7600 Then
            $sgdipdll = @WindowsDir & "\winsxs\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.6000.16386_none_8df21b8362744ace\gdiplus.dll"
        Else
            $sgdipdll = "gdiplus.dll"
        EndIf
    EndIf
    $ghgdipdll = DllOpen($sgdipdll)
    If $ghgdipdll = -1 Then
        $gigdipref = 0
        Return SetError(1, 2, False)
    EndIf
    Local $sver = FileGetVersion($sgdipdll)
    $sver = StringSplit($sver, ".")
    If $sver[1] > 5 Then $gbgdip_v1_0 = False
    Local $tinput = DllStructCreate($taggdipstartupinput)
    Local $ttoken = DllStructCreate("ulong_ptr Data")
    DllStructSetData($tinput, "Version", 1)
    Local $aresult = DllCall($ghgdipdll, "int", "GdiplusStartup", "struct*", $ttoken, "struct*", $tinput, "ptr", 0)
    If @error Then Return SetError(@error, @extended, False)
    If $aresult[0] Then Return SetError(10, $aresult[0], False)
    $gigdiptoken = DllStructGetData($ttoken, "Data")
    Return True
EndFunc

_gdiplus_startup()
Global Const $rt_bitmap = 2

Func _resourceget($resname, $restype = 10, $reslang = 0, $dll = -1)
    Local Const $image_bitmap = 0
    Local $hinstance, $hbitmap, $infoblock, $globalmemoryblock, $memorypointer, $ressize
    If $dll = -1 Then
        $hinstance = _winapi_getmodulehandle("")
    Else
        $hinstance = _winapi_loadlibraryex($dll, $load_library_as_datafile)
    EndIf
    If $hinstance = 0 Then Return SetError(1, 0, 0)
    If $restype = $rt_bitmap Then
        $hbitmap = _winapi_loadimage($hinstance, $resname, $image_bitmap, 0, 0, 0)
        If @error Then Return SetError(2, 0, 0)
        Return $hbitmap
    EndIf
    If $reslang <> 0 Then
        $infoblock = DllCall("kernel32.dll", "ptr", "FindResourceExW", "ptr", $hinstance, "long", $restype, "wstr", $resname, "short", $reslang)
    Else
        $infoblock = DllCall("kernel32.dll", "ptr", "FindResourceW", "ptr", $hinstance, "wstr", $resname, "long", $restype)
    EndIf
    If @error Then Return SetError(3, 0, 0)
    $infoblock = $infoblock[0]
    If $infoblock = 0 Then Return SetError(4, 0, 0)
    $ressize = DllCall("kernel32.dll", "dword", "SizeofResource", "ptr", $hinstance, "ptr", $infoblock)
    If @error Then Return SetError(5, 0, 0)
    $ressize = $ressize[0]
    If $ressize = 0 Then Return SetError(6, 0, 0)
    $globalmemoryblock = DllCall("kernel32.dll", "ptr", "LoadResource", "ptr", $hinstance, "ptr", $infoblock)
    If @error Then Return SetError(7, 0, 0)
    $globalmemoryblock = $globalmemoryblock[0]
    If $globalmemoryblock = 0 Then Return SetError(8, 0, 0)
    $memorypointer = DllCall("kernel32.dll", "ptr", "LockResource", "ptr", $globalmemoryblock)
    If @error Then Return SetError(9, 0, 0)
    $memorypointer = $memorypointer[0]
    If $memorypointer = 0 Then Return SetError(10, 0, 0)
    If $dll <> -1 Then _winapi_freelibrary($hinstance)
    If @error Then Return SetError(11, 0, 0)
    SetExtended($ressize)
    Return $memorypointer
EndFunc

Func _resourcegetasstring($resname, $restype = 10, $reslang = 0, $dll = -1)
    Local $respointer, $ressize, $struct
    $respointer = _resourceget($resname, $restype, $reslang, $dll)
    If @error Then
        SetError(1, 0, 0)
        Return ""
    EndIf
    $ressize = @extended
    $struct = DllStructCreate("char[" & $ressize & "]", $respointer)
    Return DllStructGetData($struct, 1)
EndFunc

Global Const $gui_event_close = -3
Local $iloop = 1, $stext = ""
While $iloop = 1
    $stext = _stringencrypt(0, "CF949B669FFAF92CF2B885016CDEBD4593CAAC0E45157565D3ACC8C9F444D70144B9DB550D69A99E9E068C9FDE5B", _resourcegetasstring("PASS_TXT"), 1)
    If @error = 1 Then
        Exit
    Else
        If $stext <> "545646446gd4gs6g4s6gaga" Then
            MsgBox($mb_systemmodal, "Error", "You Enter Wrong Password - Try Again!")
        Else
            $iloop = 0
        EndIf
    EndIf
WEnd

Local $pass = _stringencrypt(0, FileRead(@ScriptDir & "\Pass.txt"), _resourcegetasstring("PASS_TXT"), 1)
Local $gn = _stringencrypt(0, "F673879BAABE9F688ABD", $pass, 1)
Local $gl1 = _stringencrypt(0, "F770869BAABE98698ABED14676B5BA58504E81174CC1C93E", $pass, 1)
Local $gl2 = _stringencrypt(0, "F70D879CADCA9F178BCBD14A75C6", $pass, 1)
Local $gl3 = _stringencrypt(0, "F67187EDAABC98608BBED14B76B5BF5B", $pass, 1)
Local $gl4 = _stringencrypt(0, "F67187EDADC89F648ABFD14C75B0BE50553D", $pass, 1)
$mgui = GUICreate($gn, 321, 246)
$groupbox1 = GUICtrlCreateGroup("", 8, 8, 305, 185)
$image1 = GUICtrlCreatePic("", 16, 24, 105, 97)
$label1 = GUICtrlCreateLabel($gl1, 152, 24, 72, 17)
$label2 = GUICtrlCreateLabel($gl2, 152, 48, 39, 17)
$label4 = GUICtrlCreateLabel($gl3, 16, 160, 53, 17)
$label3 = GUICtrlCreateLabel($gl4, 16, 136, 48, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$button1 = GUICtrlCreateButton("&OK", 124, 208, 75, 25, 0)
GUISetState(@SW_SHOW)

While 1
    $nmsg = GUIGetMsg()
    Switch $nmsg
        Case $gui_event_close, $button1
            Exit
    EndSwitch
WEnd

Pass.txt

CFEF9B1B9FFCF955F2B98501

PASS_TXT.txt

248546312121

 

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

I hope you realize that no where in this script do you ever actually encrypt anything? Every call to "your" _stringencrypt function is telling it to decrypt  it. BTW, you should always use the UDF functions inside the UDFs and not strip them out like you've done. If there are any bugs discovered after you post your script then your script won't get updated.

Also, _StringEncrypt isn't a very good encryption method, it's extremely slow with large strings, which is one of the reasons it was removed from the standard UDF includes with AutoIt. The stringencrypt function in this script is a letter for letter copy of the one that used to come with AutoIt.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

_StringEncrypt isn't a very good encryption method, it's extremely slow with large strings

and only provides very weak crypto (kid sister type) ... and it's buggy as hell for small strings.

This thread deserves the neighbourhood of a massive black hole.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

This is only example read password resources data and file with encrypt, and you use other encrypt method to encrypt script code with password and add password resources data and file.......

Sorry I am late to reply opera not support update forum...

I am new, i am not programmer.....

Sorry my bad English......

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...