Advertisement
Python253

num_key_alpha_freq_cipher

Mar 5th, 2024
815
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Filename: num_key_alpha_freq_cipher.py
  4.  
  5. """
  6. This script takes user input, counts the occurrences of each letter in the alphabet, and generates a numerical key representing the frequency of each letter.
  7. The script then displays the user input, the alphabet, and the corresponding numerical key that can be used in other scripting easily.
  8.  
  9. Example Output:
  10.    Enter your string: hello world!
  11.  
  12.    User Input:  hello world!
  13.                    abcdefghijklmnopqrstuvwxyz
  14.    Numerical Key:  00011001000300200100001000
  15. """
  16.  
  17. # Global Variable Alphabet
  18. alphabet = 'abcdefghijklmnopqrstuvwxyz'
  19.  
  20. def count_letters(input_string):
  21.     letter_count = {char: 0 for char in alphabet}
  22.  
  23.     for char in input_string:
  24.         if char.isalpha():
  25.             letter_count[char.lower()] += 1
  26.  
  27.     count_string = ''.join(str(letter_count[char]) for char in alphabet)
  28.     return count_string
  29.  
  30. # Get User Input
  31. user_input = input("Enter your string: ")
  32. num_key = count_letters(user_input)
  33.  
  34. print('\nUser Input: ', user_input, '\n')
  35. print('\t\t' + alphabet)
  36. print('Numerical Key: ', num_key)
  37.  
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement