
Security News
Follow-up and Clarification on Recent Malicious Ruby Gems Campaign
A clarification on our recent research investigating 60 malicious Ruby gems.
home : https://hg.sr.ht/~ged/LSystem
code : https://hg.sr.ht/~ged/LSystem
github : https://github.com/ged/lsystem
docs : https://deveiate.org/code/lsystem
A toolkit for creating and using Lindenmayer Systems (L-systems). It consists of a class that allows for declaration of the L-system's grammar, and another class that allows for the definition of how the symbols output by a grammar should be translated into work.
Most of these were stolen from the examples on Wikipedia, and can be found in the examples/
directory of the source.
Lindenmayer's original L-system for modelling the growth of algae.
Declare the rules:
algae = LSystem.declare do
variables :A, :B
axiom 'A'
rules 'A -> AB',
'B -> A'
end
then iterate it 8 times and print out each generation:
iter = algae.each
8.times do |i|
puts "n = %d : %s" % [ i, iter.next ]
end
This outputs:
n = 0 : A
n = 1 : AB
n = 2 : ABA
n = 3 : ABAAB
n = 4 : ABAABABA
n = 5 : ABAABABAABAAB
n = 6 : ABAABABAABAABABAABABA
n = 7 : ABAABABAABAABABAABABAABAABABAABAAB
You can also do more complex tasks with the symbols in each generation. For example, to generate pretty pictures.
Declare the rules:
fern = LSystem.declare do
variables 'X', 'F'
constants '+', '-', '[', ']'
axiom 'X'
rules \
'X → F+[[X]-X]-F[-FX]+X',
'F → FF'
end
Then hook them up to a Logo interpreter ([a monkeypatched version][tortoise-patch] of the [Tortoise gem][tortoise-gem]):
LSystem.run( fern, 8 ) do
# The size of the canvas to draw on
CANVAS_SIZE = 2000
# F: draw forward
# X : no-op
# -: turn left 25°
# +: turn right 25°
# [: push position and angle
# ]: pop position and angle
production_map \
'F' => :forward,
'-' => :turn_left,
'+' => :turn_right,
'[' => :save_pos_and_angle,
']' => :restore_pos_and_angle
### Set up some instance variables
def initialize( * )
super
@turtle = nil
@positions = []
end
on_start do |i, _|
@turtle = Tortoise::Interpreter.new( CANVAS_SIZE )
@turtle.setpos( CANVAS_SIZE / 2, 0 )
@turtle.direction = 90
@turtle.pd
end
on_finish do |i, _|
File.open( "fern_gn#{i}.png", File::WRONLY|File::TRUNC|File::CREAT, 0644, encoding: 'binary' ) do |fh|
fh.write( @turtle.to_png )
end
end
### Draw a line forward
def forward
@turtle.fd( 5 )
end
### Turn 25° to the left
def turn_left
@turtle.lt( 25 )
end
### Turn 25° to the right
def turn_right
@turtle.rt( 25 )
end
### Save the drawing position and angle
def save_pos_and_angle
@positions.push([ @turtle.position, @turtle.direction ])
end
### Restore the next saved position and angle
def restore_pos_and_angle
to_restore = @positions.pop or raise IndexError, "Position stack underflow"
@turtle.setpos( *to_restore.first )
@turtle.direction = to_restore.last
end
end
This generates a sequence of images, which for generation 8 yields:
$ gem install lsystem
You can check out the current development source with Mercurial via its project page. Or if you prefer Git, via its Github mirror.
After checking out the source, run:
$ rake setup
This task will install dependencies, and do any other necessary setup for development.
Copyright (c) 2020, Michael Granger All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the author/s, nor the names of the project's contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
FAQs
Unknown package
We found that l_system demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.
Security News
ESLint now supports parallel linting with a new --concurrency flag, delivering major speed gains and closing a 10-year-old feature request.
Research
/Security News
A malicious Go module posing as an SSH brute forcer exfiltrates stolen credentials to a Telegram bot controlled by a Russian-speaking threat actor.