'已知a、b,求x,满足a*x =1 (mod b),相当于求解a*x-b*y=1的最小整数解(此函数有问题)
Public Function BigEuclid(ByVal aString As String, ByVal bString As String) As String
Dim m As String, e As String, si As String, sj As String, x As String, y As String
Dim xx As Long, yy As Long
m = bString
e = aString
x = "0"
y = "1"
xx = 1
yy = 1
Do While (e > "0")
Call TextToBigNumber(m, AAAA, LengthAAAA)
Call TextToBigNumber(e, BBBB, LengthBBBB)
Call DivBInt(AAAA, LengthAAAA, BBBB, LengthBBBB, CCCC, LengthCCCC, DDDD, LengthDDDD)
si = BigNumberToText(CCCC, LengthCCCC)
sj = BigNumberToText(DDDD, LengthDDDD)
m = e
e = sj
sj = y
y = BigMul(y, si)
If (xx = yy) Then
If ((x > y) And (Len(x) = Len(y)) Or (Len(x) > Len(y))) Then
y = BigSub(x, y)
Else 'NOT (X...'NOT ((X...
y = BigSub(y, x)
yy = 0
End If
Else 'NOT (XX...
y = BigAdd(y, x)
xx = 1 - xx
yy = 1 - yy
End If
x = sj
Loop
If (xx = 0) Then
x = BigSub(bString, x)
End If
BigEuclid = x
Private Sub TextToBigNumber(Tekst As String, A() As Long, LengthA As Long)
Dim i As Long
Dim Prvi As String
Dim MaxLengthPrvi As Long
Dim Ostatak As Long
Prvi = Trim$(Tekst)
If IsBigNum(Prvi) Then
A(0) = 0
If Left$(Prvi, 1) = "+" Then
Prvi = Right$(Prvi, Len(Prvi) - 1)
End If
If Left$(Prvi, 1) = "-" Then
Prvi = Right$(Prvi, Len(Prvi) - 1)
A(0) = -1
End If
MaxLengthPrvi = Len(Prvi)
If (MaxLengthPrvi \ 4) * 4 = MaxLengthPrvi Then
LengthA = MaxLengthPrvi \ 4
For i = 1 To LengthA
A(i) = Mid$(Prvi, MaxLengthPrvi - i * 4 + 1, 4)
Next i
Else 'NOT (MaxLengthPRVI...
LengthA = MaxLengthPrvi \ 4 + 1
Ostatak = MaxLengthPrvi Mod 4
For i = 1 To LengthA - 1
A(i) = Mid$(Prvi, MaxLengthPrvi - i * 4 + 1, 4)
Next i
A(LengthA) = Mid$(Prvi, 1, Ostatak)
End If
Else 'IsBigNum(PRVI) = FALSE
A(1) = 0
LengthA = 1
End If