Cipolla's algorithm: Difference between revisions
m
→GMP version: a few small tweaks
m (→{{header|Sage}}: Changed - to +, also a few efficiency updates for dealing with large numbers) |
m (→GMP version: a few small tweaks) |
||
Line 364:
===GMP version===
{{libheader|GMP}}
<lang freebasic>' version
' compile with: fbc -s console
Line 370:
Type fp2
x As
y As
End Type
Line 383:
Data "34035243914635549601583369544560650254325084643201" ', 10^50 + 151
Function fp2mul(a As fp2, b As fp2, p As
Dim As fp2 r
r.x = Allocate(Len(
r.y = Allocate(Len(
Return r
Line 401:
End Function
Function fp2square(a As fp2, p As
Return fp2mul(a, a, p, w2)
Line 407:
End Function
Function fp2pow(a As fp2, n As
If
Return a
End If
If
If
If
Return fp2square(fp2pow(a, n, p, w2), p, w2)
Else
Return fp2mul(a, fp2pow(a, n, p, w2), p, w2)
End If
Line 428:
' ------=< MAIN >=------
Dim As Long i
Dim As ZString Ptr zstr
Dim As String n_str, p_str
Dim As
a = Allocate(Len(
n = Allocate(Len(
p = Allocate(Len(
p2 = Allocate(Len(
w2 = Allocate(Len(
x1 = Allocate(Len(
x2 = Allocate(Len(
Dim As fp2 answer
answer.x = Allocate(Len(
answer.y = Allocate(Len(
For i = 1 To 8
Read n_str
If i < 8 Then
Read p_str
Else
p_str = "10^50 + 151" ' set up last n
End If
Print "Find solution for n = "; n_str; " and p = "; p_str
Print p_str; "is not a odd prime"
Print
Line 467 ⟶ 466:
' p is checked and is a odd prime
▲ If result <> 1 Then
Print n_str; " is not a square in F"; p_str
Print
Line 475 ⟶ 473:
End If
Do
Do
Do
Loop Until
answer = fp2pow(answer, p2, p, w2)
Loop Until
If
Loop
Line 506 ⟶ 504:
Next
' empty keyboard buffer
|