Created
September 11, 2022 14:14
-
-
Save PeterZhizhin/892ea35fdeba95e9824de0179e7923cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generated by the protocol buffer compiler. DO NOT EDIT! | |
# source: choices.proto | |
import sys | |
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) | |
from google.protobuf import descriptor as _descriptor | |
from google.protobuf import message as _message | |
from google.protobuf import reflection as _reflection | |
from google.protobuf import symbol_database as _symbol_database | |
# @@protoc_insertion_point(imports) | |
_sym_db = _symbol_database.Default() | |
DESCRIPTOR = _descriptor.FileDescriptor( | |
name='choices.proto', | |
package='', | |
syntax='proto3', | |
serialized_options=None, | |
serialized_pb=_b('\n\rchoices.proto\"\x17\n\x07\x43hoices\x12\x0c\n\x04\x64\x61ta\x18\x01 \x03(\rb\x06proto3') | |
) | |
_CHOICES = _descriptor.Descriptor( | |
name='Choices', | |
full_name='Choices', | |
filename=None, | |
file=DESCRIPTOR, | |
containing_type=None, | |
fields=[ | |
_descriptor.FieldDescriptor( | |
name='data', full_name='Choices.data', index=0, | |
number=1, type=13, cpp_type=3, label=3, | |
has_default_value=False, default_value=[], | |
message_type=None, enum_type=None, containing_type=None, | |
is_extension=False, extension_scope=None, | |
serialized_options=None, file=DESCRIPTOR), | |
], | |
extensions=[ | |
], | |
nested_types=[], | |
enum_types=[ | |
], | |
serialized_options=None, | |
is_extendable=False, | |
syntax='proto3', | |
extension_ranges=[], | |
oneofs=[ | |
], | |
serialized_start=17, | |
serialized_end=40, | |
) | |
DESCRIPTOR.message_types_by_name['Choices'] = _CHOICES | |
_sym_db.RegisterFileDescriptor(DESCRIPTOR) | |
Choices = _reflection.GeneratedProtocolMessageType('Choices', (_message.Message,), dict( | |
DESCRIPTOR = _CHOICES, | |
__module__ = 'choices_pb2' | |
# @@protoc_insertion_point(class_scope:Choices) | |
)) | |
_sym_db.RegisterMessage(Choices) | |
# @@protoc_insertion_point(module_scope) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from nacl.public import PrivateKey, PublicKey, Box | |
import choices_pb2 | |
def decode_proto(message): | |
offset = ((message[0] << 8) | message[1]) + 2 | |
original_message = message[offset:] | |
result = choices_pb2.Choices().FromString(original_message) | |
return list(result.data) | |
def decrypt_ballot(ballot, private_key='e6d2d34b20b9aeb8140b29a854ba35e6c83c29cdec54c96404ae1146c781875e'): | |
cipher, nonce, public_key = ballot | |
private = PrivateKey(bytes.fromhex(private_key)) | |
public = PublicKey(bytes.fromhex(public_key)) | |
box = Box(private, public) | |
message = box.decrypt(bytes.fromhex(cipher), nonce=bytes.fromhex(nonce)) | |
return decode_proto(message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment