is the shapes are always going to be squares, a faster way would to get their bounding box(exactWorldBoundingBox command), find the difference and scale the smaller one accordingly.
to match the position you can get the rotatePivot position of the bigger square (if the pivot is in the center of the square) with the xform command and set the smaller square's worldSpace position to that. (using "ws" flag)