Created
September 22, 2011 18:36
-
-
Save hakagura/1235601 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def traffic | |
traffic=File.open('self.csv','r'){|file| file.readlines.collect{|line| line.chomp.split("|").map{|c| c.to_i.to_s(2)}.map{|c| c.rjust(40,"0")}.join()}} | |
return traffic | |
end | |
def detector | |
chars = ("0".."0").to_a + ("1".."1").to_a + ("0".."1").to_a | |
random = "" | |
1.upto(280) { |i| random << chars[rand(chars.size-1)] } | |
return random | |
end | |
def rcont(string1, string2,limit) | |
count=0 | |
max=0 | |
tamanho = string2.split('').size | |
retorno=false | |
tamanho.times do |n| | |
if (string1.split('').take(limit) == string2.split('').take(limit)) | |
count=count+1 | |
else | |
count=0 | |
end | |
if (count>max) | |
max=count | |
end | |
if (count>max) | |
max=count | |
end | |
if (max >= limit) | |
retorno=true | |
break | |
end | |
end | |
return retorno | |
end | |
def testar_combinacao(pseudo_detector, traffics, limit) | |
for traffic in traffics do | |
if rcont(pseudo_detector,traffic,limit) | |
return true | |
end | |
end | |
return false | |
end | |
def gerar_detectores(traffics,max_detectors) | |
file=File.new("Detectores.txt",'a+') | |
quant = 0 | |
while quant < max_detectors do | |
pseudo_detector = detector | |
if (testar_combinacao(pseudo_detector, traffics, 10)) == true | |
file.puts pseudo_detector | |
quant = quant + 1 | |
end | |
end | |
file.close | |
end | |
if __FILE__ == $0 | |
max_detectors = 1 | |
traffics = traffic | |
detec = detector | |
gerar_detectores(traffic,max_detectors) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment