.


:




:

































 

 

 

 


VBA WordMSOffice.

  : 02-071-1 .. : ..    

2018

: , bruteforce, , .

:

1. - (bruteforce).

X =
X  
X 0  
X

 

 


2. ( 10 ) .

' word

 

Function GetFilePath(Optional ByVal title As String = "", _

Optional ByValInitialPathAs String = "c:\", _

Optional ByValFilterDescriptionAs String = " Excel", _

Optional ByValFilterExtentionAs String = "*.xls*") As String

' Title,

' InitialPath

' ,

'

On Error Resume Next

With Application.FileDialog(msoFileDialogOpen)

.ButtonName = "":.title = title:.InitialFileName = InitialPath

.Filters.Clear:.Filters.AddFilterDescription, FilterExtention

If.Show <> -1 Then Exit Function

GetFilePath =.SelectedItems(1): PS = Application.PathSeparator

End With

End Function

' Word() progressbar

 

 

Sub Word()

Dim t!

Dim i As Integer, j As Integer, k As Integer

Dim l As Integer

Dim s As Integer

Dim kennwort As String

t = Timer

OnErrorResumeNext

' ,

' , ,

NameFile = GetFilePath(" Word",, " Word", "*.docx") '

IfNameFile = "" ThenExitSub ' ,

Dim objWrdApp As Object

Dim objWrdDoc As Object

Set objWrdApp = GetObject(, "Word.Application")

If objWrdAppIs Nothing Then

Set objWrdApp = CreateObject("Word.Application")

End If

Dim bar As Progressbar '

Setbar = NewProgressbar

'

' , ..

' . ,

bar.createtimeFinish '

bar.createLoadingBar '

'bar.createString '

bar.createtimeDuration '

'bar.createTextBox '

bar.setParameters 100000, 0, 1 ' :

' 1 - ;

' 2 - , ,

' 3 - , , _

 

bar.Start " " '

s = 0

For i = 0 To 5

For j = 0 To 5

For k = 0 To 5

For l = 0 To 5

kennwort = CStr(i) &CStr(j) &CStr(k) &CStr(l)

s = s + 1

bar.Update s * 100 '

Set objWrdDoc = objWrdApp.Documents.Open(NameFile, PasswordDocument:=kennwort)

objWrdApp.Visible = True

If Err Then

Err.Clear

 

Else

MsgBox " = " &kennwort& " " & " "& Format(Timer - t, "0.0 ")

UserForm4.TextBox1.Text = ""

bar.exitBar '

Setbar = Nothing '

Exit Sub

End If

Next

Next

Next

Next

Set objWrdDoc = Nothing

Set objWrdApp = Nothing

EndSub

 

3. . .

(30 ), (10 ), (52 ), (66 ), 30 + 10 + 52 + 66 = 158. 10 158^10 9 695 514 708 609 891 533 824 . , 307 442 754 585 549 , .


 

4. - .

 

( )  
-?
( )  
, , ,
?

 



5. VBA

'

 

PublicSchetAsByte

PublicParFr, ParFr1, ParFr2 AsString ',

DimPriznakM(26) AsByte ',

DimPriznakB(26) AsByte ',

DimSformMAsString ' , Generator

DimSformBAsString ' , Generator

DimObrMAsString ' , Generator

DimObrBAsString ' , Generator

DimPovtorAsByte '=0, , =1,

DimbukAsBoolean ' =, ()

ConstNALU = "abcdefghijklmnopqrstuvwxyz" '

ConstNAL = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" '

'

 

Sub()

' . .

' .

' , , ,

' ,

ParFr = "Pupils come to the library to take books on different subjects"

'

IfSchet = 0 ThenParFr1 = ParFr

ParFr2 = InputBox("", " ", ParFr1)

IfLen(ParFr2) < 6 Then

MsgBox " , "

ParFr2 = ParFr1

If Povtor = 1 Then GoTo mm

EndIf

ParFr1 = ParFr2

Schet = Schet + 1 '

Fori = 1 To 26

PriznakM(i) = 0 '

PriznakB(i) = 0 '

Next i

SformM = Empty

SformB = Empty

NsformM = 0

NsformB = 0

For i = 1 To Len(ParFr2)

Sim1 = Mid(ParFr2, i, 1) ' i-

buk = False

Forj = 1 To 26 ' ,

If Sim1 = Mid(NALU, j, 1) Then buk = True

Next j

If buk = True Then

Forj = 1 ToNsformM

IfSim1 = Mid(SformM, j, 1) ThenGoTom '

Nextj

SformM = SformM + Sim1 ' ,

IndexM = Asc(Sim1) - Asc("a") + 1 '

PriznakM(IndexM) = 1 '

NsformM = NsformM + 1 ' -

Else

Forj = 1 To 26 '

If Sim1 = Mid(NAL, j, 1) Then buk = True

Next j

If buk = True Then

For j = 1 ToNsformB

If Sim1 = Mid(SformB, j, 1) Then GoTo m '

Nextj

SformB = SformB + Sim1 ' ,

IndexB = Asc(Sim1) - Asc("A") + 1 '

PriznakB(IndexB) = 1 '

NsformB = NsformB + 1 ' -

End If

End If

m:

Nexti

'

' ,

Fori = 1 To 26

Sim1 = Mid(NALU, i, 1) ' i-

IfPriznakM(i) = 0 Then '

SformM = SformM + Sim1 '

IndexM = Asc(Sim1) - Asc("a") + 1 '

PriznakM(IndexM) = 1 '

NsformM = NsformM + 1 ' -

End If

Next i

For i = 1 To 26

Sim1 = Mid(NAL, i, 1) ' i-

IfPriznakB(i) = 0 Then '

SformB = SformB + Sim1 '

IndexB = Asc(Sim1) - Asc("A") + 1 '

PriznakB(IndexB) = 1 '

NsformB = NsformB + 1 ' -

EndIf

Nexti

'

'

ObrM = Empty

ObrB = Empty

For i = 1 To 26

Sim1 = Mid(NALU, i, 1) '

Forj = 1 To 26

IfSim1 = Mid(SformM, j, 1) ThenIndex1 = j '

Nextj

Sim2 = Mid(NALU, Index1, 1) '

ObrM = ObrM + Sim2 '

Next i

For i = 1 To 26

Sim1 = Mid(NAL, i, 1) '

Forj = 1 To 26

IfSim1 = Mid(SformB, j, 1) ThenIndex1 = j '

Nextj

Sim2 = Mid(NAL, Index1, 1) '

ObrB = ObrB + Sim2 '

Nexti

'

Povtor = 1 '

mm:

EndSub

'

 

PublicSub() '

' (, ..)

' 1 ()

' Generator

'

'

' , .. ,

'

Dim Sim, ALU As String, Sym1 As Variant

Dim Index As Integer

Dim Result As String

Result = Empty

NChar = Selection.Start

NChar1 = Selection.End

IfNChar = NChar1 Then

CallMsgBox(" ", 64, "")

GoTo mm

End If

If Povtor<> 1 Then

Else

o1 = MsgBox(ParFr1, 3, " , ?")

If o1 <> 6 Then GoTo mm

End If

ALU = SformM

AL = SformB

'

For Each Sym1 InSelection.Characters

Sym = Sym1

Select Case Sym

Case "A" To "Z" '

'

IndexB = Asc(Sym) - Asc("A") + 1

' AL

Sym = Mid(AL, IndexB, 1)

Case "a" To "z" '

'

IndexM = Asc(Sym) - Asc("a") + 1

' ALU

Sym = Mid(ALU, IndexM, 1)

Case Else

'Sym = Empty

EndSelect

'

Result = Result + Sym

NextSym1

'

Selection.LanguageID = wdRussian

Selection.TypeText Result '

UserForm4.TextBox1.Text = ""

mm:

EndSub

'

 

PublicSub() '

' (, ..)

'

' 1 ()

' Generator

Dim Sim, ALUoAs String, Sym1 As Variant

Dim Index As Integer

Dim Result As String

Result = Empty

' , ?

NChar = Selection.Start

NChar1 = Selection.End

IfNChar = NChar1 Then

CallMsgBox(" ", 64, "")

GoTomm

EndIf

'IfPovtor<> 1 ThenGenerator ' -

IfPovtor<> 1 Then

Else

o1 = MsgBox(ParFr1, 3, " , ?")

If o1 <> 6 Then GoTo mm

End If

'ALUo = ObrM

'ALo = ObrB

'

For Each Sym1 InSelection.Characters

Sym = Sym1

Select Case Sym

Case "A" To "Z" '

'

IndexB = Asc(Sym) - Asc("A") + 1

' AL

Sym = Mid(ObrB, IndexB, 1)

Case "a" To "z" '

'

IndexM = Asc(Sym) - Asc("a") + 1

' ALU

Sym = Mid(ObrM, IndexM, 1)

Case Else

'Sym = Empty

EndSelect

'

Result = Result + Sym

NextSym1

'

Selection.LanguageID = wdRussian

Selection.TypeText Result '

UserForm4.TextBox1.Text = " "

mm:

 

End Sub

Sub ()

UserForm4.Show

EndSub

 

:

, VBA. . Word, : , , , .

, ( 10) , .

 



<== | ==>
5 |
:


: 2018-11-11; !; : 442 |


:

:

, .
==> ...

1620 - | 1541 -


© 2015-2024 lektsii.org - -

: 0.128 .