Smart and sustainable cities require a network that can ensure many exchanges of information. In this sense, the deployment of optical fiber seems essential in order to guarantee urban interconnection. In this work, a new algorithm for the right shift code to be used in optical fiber communication (OFC) is proposed. The algorithm was designed to support different quality of services (audio, video, and data) for smart cities. This algorithm was based on varying the code weight for a certain number of users and transmitting a service to them. This algorithm was used for a spectral amplitude-coding optical code division multiple-access (SAC-OCDMA) system. Two detection scheme approaches were used, which are the single photodiode (SPD) detection technique and the direct detection (DD) technique. The performance was analytically studied for the proposed system in terms of BER, SNR, and the maximum number of users. The obtained results, when our system used SPD, showed an improvement in the number of users, about 2.5% at 622 Mbps and 1.4% at 1.25 Gbps and 2.5 Gbps. It can support a number of users up to 151 for video services at BER = , 300 for audio services with BER = , and 162 for data services at BER = at a data rate of 1.25 Gbps. Furthermore, the system was simulated and showed transmission distances of 30 km at 1.25 Gbps and 6 km at 2.5 Gbps for video services, 80 km at 1.25 Gbps and 30 km at 2.5 Gbps for audio services, and 44 km at 1.25 Gbps and 13 km at 2.5 Gbps for data services. Our proposed system is suggested to be implemented in a fixed fifth-generation passive optical network (F5G PON).