Devide 12v square wave signal and output 5v squarewave

Sorry I was getting confused, the input and outputs are not PWM and are sqaure wave.

This is the code which I have come up with so far, the maths should be correct, and give you an idea of what I'm trying todo. What I'm unsure about is how to read in a sqaure wave and save the pulses as a variable, aslo read a variable and output as sqaure wave??

here is my code so far:

/*
Read square wave speed signal in on pin2 and output squarewave speed on pin4
 */


const int speed_in = 2; //sqaure wave input from speed source 
const int gear_in = 3;     //gear select input 
const int speed_out = 4; //sqaure wave output

// variables for calculation
const float ratio1 = 1/ 2.315;
const float ratio2 = 1/ 1.731;
const float FD = 1 / 4.7;
const float idler = 1.04;
const float pulses = 4; //pulses per simultated revolution
float square_in; //speed received
float square_out; //speed to send

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.

  pinMode(speed_in, INPUT);
  pinMode(speed_out, OUTPUT);
  pinMode(gear_in, INPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  //Sample data to test
  square_in = 23890;


/*
 read the square wave speed input from "speed_in" into variable "sqaure_in"
*/



  if (gear_in == HIGH) {        //ratio1 is selected
    square_out = square_in / 2 * ratio1 / idler * FD * pulses; 
  }//end of ratio1

  square_out = square_in / 2 * ratio2 / idler * FD * pulses;



/*
  //output the variable "sqaure_out" as square wave to "Speed_out"
*/
}