



def   __snake_case			(    _UpperCAmelCase       ):
    __a		 =       ''''''
    for ch in key:
        if ch == " " or ch not in key_no_dups and ch.isalpha():
            key_no_dups += ch
    return key_no_dups





def   __snake_case			(    _UpperCAmelCase       ):
    __a		 =       [chr(i + 65       ) for i in range(26       )]
    # Remove duplicate characters from key
    __a		 =       remove_duplicates(key.upper()       )
    __a		 =       len(_UpperCAmelCase       )
    # First fill cipher with key characters
    __a		 =       {alphabet[i]: char for i, char in enumerate(_UpperCAmelCase       )}
    # Then map remaining characters in alphabet to
    # the alphabet from the beginning
    for i in range(len(_UpperCAmelCase       )     ,				26       ):
        __a		 =       alphabet[i - offset]
        # Ensure we are not mapping letters to letters previously mapped
        while char in key:
            offset -= 1
            __a		 =       alphabet[i - offset]
        __a		 =       char
    return cipher_alphabet





def   __snake_case			(    _UpperCAmelCase     ,				_UpperCAmelCase       ):
    return "".join(cipher_map.get(_UpperCAmelCase     ,				_UpperCAmelCase       ) for ch in message.upper()       )





def   __snake_case			(    _UpperCAmelCase     ,				_UpperCAmelCase       ):
    __a		 =       {v: k for k, v in cipher_map.items()}
    return "".join(rev_cipher_map.get(_UpperCAmelCase     ,				_UpperCAmelCase       ) for ch in message.upper()       )





def   __snake_case			(    ):
    __a		 =       input('''Enter message to encode or decode: '''       ).strip()
    __a		 =       input('''Enter keyword: '''       ).strip()
    __a		 =       input('''Encipher or decipher? E/D:'''       ).strip()[0].lower()
    try:
        __a		 =       {'''e''': encipher, '''d''': decipher}[option]
    except KeyError:
        raise KeyError('''invalid input option'''       )
    __a		 =       create_cipher_map(_UpperCAmelCase       )
    print(func(_UpperCAmelCase     ,				_UpperCAmelCase       )       )


if __name__ == "__main__":
 import doctest

 doctest.testmod()
 main()










import argparse
import logging
import pickle
from collections import Counter


logging.basicConfig(
    format='''%(asctime)s - %(levelname)s - %(name)s - %(message)s''', datefmt='''%m/%d/%Y %H:%M:%S''', level=logging.INFO
)
__snake_case		:Tuple   	=  logging.getLogger(__name__)

if __name__ == "__main__":
 __snake_case		:Union[str, Any]   	=  argparse.ArgumentParser(
     description='''Token Counts for smoothing the masking probabilities in MLM (cf XLM/word2vec)'''
 )
 parser.add_argument(
     '''--data_file''', type=str, default='''data/dump.bert-base-uncased.pickle''', help='''The binarized dataset.'''
 )
 parser.add_argument(
     '''--token_counts_dump''', type=str, default='''data/token_counts.bert-base-uncased.pickle''', help='''The dump file.'''
 )
 parser.add_argument('''--vocab_size''', default=3_0522, type=int)
 __snake_case		:List[str]   	=  parser.parse_args()

 logger.info(f'Loading data from {args.data_file}')
 with open(args.data_file, '''rb''') as fp:
  __snake_case		:Optional[Any]   	=  pickle.load(fp)

 logger.info('''Counting occurrences for MLM.''')
 __snake_case		:Dict   	=  Counter()
 for tk_ids in data:
  counter.update(tk_ids)
 __snake_case		:Optional[Any]   	=  [0] * args.vocab_size
 for k, v in counter.items():
  __snake_case		:Any   	=  v

 logger.info(f'Dump to {args.token_counts_dump}')
 with open(args.token_counts_dump, '''wb''') as handle:
  pickle.dump(counts, handle, protocol=pickle.HIGHEST_PROTOCOL)





