Skip to content

Feat/rg module#6

Open
Catskhi wants to merge 2 commits intofullzer4:mainfrom
Catskhi:feat/rg-module
Open

Feat/rg module#6
Catskhi wants to merge 2 commits intofullzer4:mainfrom
Catskhi:feat/rg-module

Conversation

@Catskhi
Copy link
Copy Markdown

@Catskhi Catskhi commented May 4, 2026

No description provided.

Catskhi added 2 commits May 3, 2026 23:32
- Implemented RG parsing, validation, formatting, and generation in core and wasm bindings.
- Added support for RG check digit computation and symbol removal.
- Created tests for RG functionality, including strict and lenient validation cases.
- Updated parity generation tool to include RG cases.
Comment thread core/src/rg.rs
const SP_BODY_LEN: u8 = 9;
const SP_FORMATTED_LEN: u8 = 12;
const SP_BASE_LEN: usize = 8;
const SP_WEIGHTS: [u32; SP_BASE_LEN] = [2, 3, 4, 5, 6, 7, 8, 9];
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrigir este bug saca pai:

O SP_WEIGHTS ta [2, 3, 4, 5, 6, 7, 8, 9] com sum % 11, mas o correto e [9, 8, 7, 6, 5, 4, 3, 2]. Os testes passam porque geram e validam com o mesmo peso errado, mas RGs reais de SP nao batem

Script que valida isto:

WEIGHTS_PR = [2, 3, 4, 5, 6, 7, 8, 9]
WEIGHTS_FIX = [9, 8, 7, 6, 5, 4, 3, 2]

rgs = [
    ([2,9,4,6,5,3,2,7], 2),  # fonte: bosontreinamentos.com.br
    ([3,9,4,0,6,7,1,4], 9),  # fonte: dev.to/shadowlik
]

for digits, dv in rgs:
    s = "".join(map(str, digits))
    got_pr  = sum(d*w for d,w in zip(digits, WEIGHTS_PR)) % 11
    got_fix = sum(d*w for d,w in zip(digits, WEIGHTS_FIX)) % 11
    print(f"RG {s}-{dv}  PR=[2..9]→{got_pr} {'✗' if got_pr!=dv else '✓'}  fix=[9..2]→{got_fix} {'✓' if got_fix==dv else '✗'}")

Output:

RG 29465327-2  PR=[2..9]→9 ✗  fix=[9..2]→2 ✓
RG 39406714-9  PR=[2..9]→2 ✗  fix=[9..2]→9 ✓

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants