Login Register






[Source] Glibberish-O-Mat filter_list
Author
Message
[Source] Glibberish-O-Mat #1
Have you ever wondered how spam bots create their spam messages?

This is probably how: They use Markov-Chains.
Given one word as input, a Markov Chain will put out another word. The output word is defined by a certain probability. It might be word A with probability of 20% or word B with probability of 80%. This word output is again used as input to get the next word, thus forming a chain of words.

This is my Glibberish-O-Mat that uses this principle. It takes as input a text file (you can use one from Project Gutenberg to get a reasonably long text: http://www.gutenberg.org/ebooks/search/?...=downloads ), analyses the probabilities of the words following other words and then produces a text with the given amount of words using these probabilities.

Usage: glibberish.py <filename> <wordstogenerate>

Example usage: python glibberish.py pg28203.txt 100

Example output:

[Image: 7823rgf9.png]

Python source (Python 2.7):

Code:
import sys import operator import random markov_chain = {} #adds the specified word to the markov chain def add_to_chain(lastword, word): if not markov_chain.has_key(lastword): markov_chain[lastword] = {} if not markov_chain[lastword].has_key(word): markov_chain[lastword][word] = 1 else: markov_chain[lastword][word] += 1 #builds up the markov chain using the specified file def build_chain_from(filename): file = open(filename, 'r') lastword = "first" for word in words(file): add_to_chain(lastword, word) lastword = word #iterates over words in a file def words(file): for line in file: for word in line.split(): yield word #returns a random word with the probability based on the given lastword def get_rand_word(lastword): chain = markov_chain[lastword] total = sum(chain.itervalues()) randval = random.randint(1, total) for key in chain: randval -= chain[key] if randval <= 0: return key return "" #generates a text with the given amount of words def generate_text(amount): lastword = "first" word = get_rand_word(lastword) for i in range(0, amount): word = word + " " + get_rand_word(lastword) return word def print_title(): print(''' _____ _ _ _ _ _ _ | __ \| |(_)| | | | (_) | | | | \/| | _ | |__ | |__ ___ _ __ _ ___ | |__ | | __ | || || '_ \ | '_ \ / _ \| '__|| |/ __|| '_ \ | |_\ \| || || |_) || |_) || __/| | | |\__ \| | | | \____/|_||_||_.__/ |_.__/ \___||_| |_||___/|_| |_| _____ ___ ___ _ | _ | | \/ | | | ______ | | | | ______ | . . | __ _ | |_ |______|| | | ||______|| |\/| | / _` || __| \ \_/ / | | | || (_| || |_ \___/ \_| |_/ \__,_| \__| ''') def main(): print_title() if len(sys.argv) != 3 or not sys.argv[2].isdigit(): print "usage: markov.py <filename> <wordstogenerate>" return filename = sys.argv[1] amount = int(sys.argv[2]) build_chain_from(filename) print generate_text(amount) print main()
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply

RE: [Source] Glibberish-O-Mat #2
Gutenberg website link is not added properly.

Reply

RE: [Source] Glibberish-O-Mat #3
(04-03-2013, 03:49 PM)H4R0015K Wrote: Gutenberg website link is not added properly.

Thanks for the hint. It should work now.
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply

RE: [Source] Glibberish-O-Mat #4
Nice one Deque, Added the link to the download page so that you can view the text in HTML format (View offered by the site) and copy paste it to the program Smile
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG

Reply

RE: [Source] Glibberish-O-Mat #5
Not bad, Smile I always knew that there was some formula and algorithm being used for spam bots I have seen in the past. Although probability chose the words, the probability that it would fool me appeared to have failed in the past lol.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: [Source] Glibberish-O-Mat #6
It is not to fool people but to fool anti-spam software.
Or in this case you might just use it to create some funny poems: Wink

Quote:is sound glow despair.
inspired appeared.
the despair.
time sound sensation
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply

RE: [Source] Glibberish-O-Mat #7
The only anti-spam i've ever used was a list of known spammer IP's disabled and banned from registration, among a few other registration security features. Implementing anything past that, can lead to unwanted actions sometimes, as not everybody has a certain level of quality in their posts, and not all are good English posters also, so I've never taken the risk to analyze others posts.

I have seen some good ones though that have been autogenerated! Perhaps better than some human posters which is the sad part.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply