All pastes #435542 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-04-11 23:50 UTC
rendered paste body
#!/usr/bin/env python

###########################################################################
# Copyright (C) 2007  Ryan Kavanagh                                       #
# This program is free software; you can redistribute it and/or modify    #
# it under the terms of the GNU General Public License as published by    #
# the Free Software Foundation; either version 2 of the License, or       #
# (at your option) any later version.                                     #
# This program is distributed in the hope that it will be useful,         #
# but WITHOUT ANY WARRANTY; without even the implied warranty of          #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           #
# GNU General Public License for more details.                            #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., #
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.             #
# You may contact the author at ryanakca@kubuntu.org                      #
###########################################################################

class KCipherEncrypt:
    """Class to encrypt a sentence into pig latin, ROT13"""
    def set_phrase(self, string):
        self.phrase = string
        
    def is_vowel(self, letter):
        """Determines if 'letter' is a vowel or not. Usefull for pig latin."""

        return letter in ['a', 'e', 'i', 'o', 'u']
    
    def is_punctuation(self, character):
        """Determines of 'character' is punctuation"""

        return character in ['!', '?', '.', ',', ';', ':', '"', "'"]
    
    def pig(self):
        """Ciphers self.phrase into pig latin."""
        
        self.phrase = self.phrase.split()
        
        self.encrypted_phrase = ""
        
        for word in self.phrase:
            # Is the first character a vowel? If so, just add 'ay'
            if self.is_vowel(word[0]):
                # Is the last character punctuation? If so, we need to put it
                # at the end.
                if self.is_punctuation(word[-1]):
                    self.encrypted_phrase = self.encrypted_phrase + \
                        word[:-1] + 'ay' + word[-1] + ' '
                # Last character in word is not punctuation
                else:
                    self.encrypted_phrase = self.encrypted_phrase + \
                        word + 'ay '
            # The first character is a consonnant. Move last char to end and
            # add 'ay'
            else:
                # Is the last character punctuation? If so, we need to put it
                # at the end.
                if self.is_punctuation(word[-1]):
                    self.encrypted_phrase = self.encrypted_phrase + \
                        word[1:-1] + word[0] + 'ay' + word[-1] + ' '
                # Last character in word is not punctuation
                else:
                    self.encrypted_phrase = self.encrypted_phrase + \
                        word[1:] + word[0] + 'ay '
        
        # remove the space at the end
        self.encrypted_phrase = self.encrypted_phrase[:-1]
        
        return self.encrypted_phrase
    
    def vigenere(self):
        """Ciphers self.phrase into the vigenere cipher."""