@@ -40,33 +40,40 @@ def __init__(self):
40
40
"""
41
41
self .generateCPF ()
42
42
43
+ def getDigits (cpf ):
44
+ lenQty = len (cpf ) + 1
45
+ for cpfIndex , multiplyNum in enumerate (range (lenQty , 1 )):
46
+ cpf = cpf + str (multiplyNum * int (cpf [cpfIndex ]))
47
+ return int (cpf ) % 11
48
+
49
+ def getDigitOne (cpf : str ) -> int :
50
+ return CPF_GEN .getDigits (cpf [:9 ])
51
+
52
+ def getDigitTwo (cpf : str ) -> int :
53
+ return CPF_GEN .getDigits (cpf [:10 ])
54
+
43
55
@staticmethod
44
56
def generateCPF ():
45
57
"""
46
58
This function is used to generate the CPF.
47
59
"""
48
60
49
61
# Start with random sequence between 0 and 9
50
- cpf = [random .randrange (10 ) for _ in range (9 )]
51
-
52
- for _ in range (2 ):
53
- for i , v in enumerate (cpf ):
54
- res = (len (cpf ) + 1 - i ) * v
55
-
56
- if res > 9 :
57
- res = 0
58
- else :
59
- res = 11 - res
62
+ nineDigits = "" .join ([str (random .randint (0 , 9 )) for x in range (9 )])
63
+ digitOne = CPF_GEN .getDigitOne (nineDigits )
64
+ digitTwo = CPF_GEN .getDigitTwo (f"{ nineDigits } { digitOne } " )
65
+ genCPF = f"{ nineDigits } { digitOne } { digitTwo } "
60
66
61
- cpf .append (res )
67
+ formatGenCPF = f"{ genCPF [0 :3 ]} .{ genCPF [3 :6 ]} .{ genCPF [6 :9 ]} -{ genCPF [9 :11 ]} "
68
+ logThis (f"Test formatted: { formatGenCPF } " )
62
69
63
- return "" . join ( str ( x ) for x in cpf )
70
+ return formatGenCPF
64
71
65
72
def checkCPF ():
66
73
if debugMode :
67
74
forceCPF = "113.314.390-35"
68
75
69
- if isThisValid .validateCPF (str (CPF_GEN .generateCPF ())) != True :
76
+ while isThisValid .validateCPF (str (CPF_GEN .generateCPF ())) != True :
70
77
CPF_GEN .generateCPF ()
71
78
logThis ("CPF is invalid, generating another one..." )
72
79
# logThis(f"Test Import: {isThisValid.validateCPF(str(CPF_GEN.generateCPF()))}")
0 commit comments