Spaces:
Sleeping
Sleeping
Download src/qec.py from marlonsousa/QuantumCrypt: direct link, hf CLI and curl.
- Browser
- Download file 829 Bytes
-
https://huggingface.co/spaces/marlonsousa/QuantumCrypt/resolve/main/src/qec.py
- Command line
-
hf download hf://spaces/marlonsousa/QuantumCrypt/src/qec.py
-
curl -L -o qec.py https://huggingface.co/spaces/marlonsousa/QuantumCrypt/resolve/main/src/qec.py
829 Bytes
| from typing import List | |
| class QuantumErrorCorrection: | |
| """Implementação de correção de erros quânticos.""" | |
| def encode_message(bits: List[int]) -> List[int]: | |
| """Codifica uma mensagem usando código de repetição.""" | |
| encoded = [] | |
| for bit in bits: | |
| # Implementa código de repetição de 3 qubits | |
| encoded.extend([bit] * 3) | |
| return encoded | |
| def decode_message(encoded_bits: List[int]) -> List[int]: | |
| """Decodifica uma mensagem usando voto majoritário.""" | |
| decoded = [] | |
| for i in range(0, len(encoded_bits), 3): | |
| chunk = encoded_bits[i:i+3] | |
| # Voto majoritário | |
| bit = 1 if sum(chunk) > len(chunk)/2 else 0 | |
| decoded.append(bit) | |
| return decoded | |