#! /usr/bin/python3

# Alex Desmond
# 8/26/2022
# Conversion of Arup Guha's printfreq.c to Python

# Sample Program that reads in a string and prints out a
# bar graph of its letter frequencies.

# Used to illustrate the idea of looking for a cyclic shift to match
# regular letter frequencies for shift cipher cryptanalysis.

# Set frequencies to 0.
freq = [0] * 26
max = 0

# Read in one string, set to lowercase.
cipher = input().lower()

# Go through it, looking at alphabetical characters only.
for ch in cipher:
    if (ch.isalpha()):

        # Convert character to its alphabet index (a -> 0 ... z -> 25)
        chnum = ord(ch) - ord('a')

        # Count it appropriately; 'a' is ascii offset.
        freq[chnum] += 1

        # Update max height of bar graph, if needed
        if (max < freq[chnum]):
            max = freq[chnum]

# Print from top row to bottom row, going backwards in frequency.
for i in range(max, 0, -1):

    # Go through each letter
    for j in range(26):

        # If the frequency is high enough, we print a star on this row.
        if (freq[j] >= i):
            print("*  ", end='')

        # Otherwise, a space...
        else:
            print("   ", end='')

    # Next line
    print()

# Letter footers for bar graph
for i in range(26):
    print(chr(ord('a') + i), end='  ')
print()
